Priority queue: Difference between revisions

m
→‎{{header|Perl}}: future-proof for 5.36
m (→‎{{header|Perl}}: future-proof for 5.36)
Line 5,981:
 
=={{header|Perl}}==
===Using a Module===
There are a few implementations on CPAN. Following uses <code>Heap::Priority</code>[http://search.cpan.org/~fwojcik/Heap-Priority-0.11/Priority.pm]
<syntaxhighlight lang="perl">use 5.10.0strict;
use strictwarnings;
use feature 'say';
use Heap::Priority;
 
my $h = new Heap::Priority->new;
 
$h->highest_first(); # higher or lower number is more important
Line 5,995 ⟶ 5,997:
["Tax return", 2];
 
say while ($_ = $h->pop);</syntaxhighlight>output<syntaxhighlight lang="text">Make tea
{{out}}
<pre>
Make tea
Feed cat
Clear drains
Tax return
Solve RC tasks</syntaxhighlight>
</pre>
===IBM card sorter version===
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
===IBM card sorter version===
use strict; # https://rosettacode.org/wiki/Priority_queue
<syntaxhighlight lang="perl">#!/usr/bin/perluse strict;
use warnings; # in homage to IBM card sorters :)
 
2,392

edits