Hello AppleFritter,
Heap::Simple doesn't work for me, unfortunately: it requires either Heap::Simple::XS or Heap::Simple::Perl, and both fail their test suites.
Same here (Strawberry Perl v5.22.0 on Windows 8.1, 64-bit); but Heap::Priority installed fine and seems to do the same job:
#! perl use strict; use warnings; use Heap::Priority; printf "%6d %s\n", length($_), $_ for get_N_longest(10, 'wordsEn.txt' +); sub get_N_longest { my ($min, $infile) = @_; open my $infh, '<', $infile or die "Cannot open file '$infile' for reading: $!"; my $heap = Heap::Priority->new; $heap->highest_first; while (<$infh>) { chomp; $heap->add($_, length $_); } close $infh or die "Cannot close file '$infile': $!"; my @priorities = $heap->get_priority_levels; my @r; while (@r < $min) { my $priority = shift @priorities; push @r, $heap->get_level($priority); } return @r; }
Output:
22:35 >perl heap.pl 28 antidisestablishmentarianism 25 antidisestablishmentarian 23 disestablismentarianism 23 electroencephalographic 22 counterclassifications 22 counterrevolutionaries 22 electroencephalographs 22 electroencephalography 21 antienvironmentalists 21 antiinstitutionalists 21 counterclassification 21 electroencephalograms 21 electroencephalograph 21 electrotheraputically 21 gastroenterologically 21 internationalizations 21 mechanotheraputically 21 microminiaturizations 21 microradiographically 22:35 >
Hope this is of interest,
Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^3: Size-limited, fitness-based lists
by Athanasius
in thread Size-limited, fitness-based lists
by AppleFritter
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |