For one thing, you are using a hash in the same line as you declare it with my... thats bad... I think you are trying to do something like:my %list_o_num = map { if(exists $list_o_num{$_}) { $list_o_num{$_}++ } else { $_ => 1 } } @list_o_num;
but I can't quite tell.my %list_o_num; $list_o_num{$_}++ for @list_o_num; my @true_top_3 = (sort { $b <=> $a } keys %list_o_num)[0..2]; print "T3: ", join(', ',@true_top_3), "\n";
I would probably write that like so:
#!/usr/bin/perl -wT use strict; my @list_o_num = qw(9 9 9 10 9 8 7 9 6); my %seen; my @true_top_3 = (sort { $b <=> $a } grep {!$seen{$_}++} @list_o_num)[0..2]; print "T3: ", join(', ',@true_top_3), "\n";
-Blake
In reply to Re: Answer: Find largest ordered sequence in an array
by blakem
in thread How to find the N largest values in an array?
by dubx56
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |