didnt read the whole thread but for this specific question, as you started learning perl as I've done, consider the following
use strict; use warnings; use Data::Dumper; my @AoA = ( [qw(0 Just 0)], [qw(0 Another 0)], [qw(0 Perl 0)], [qw(0 Hacker 0)], ); # see it # print Dumper \@AoA; my @sortedAoA = sort{ $a->[1] cmp $b->[1] # or reverse it comparing $b to $a instead # $b->[1] cmp $a->[1] # or use reverse function to the final array.. } @AoA; # see it # print Dumper \@sortedAoA; # then to just take first X elements use a slice for my $ar_jentry ( @sortedAoA[2..3] ){ print "$ar_jentry->[1]\n" } # output: # Just # Perl # there are other options... # you create a temporary list using sort and then use only first two e +lements with ()[0,1] print "$_->[1]\n" for ( sort{$a->[1] cmp $b->[1]} @AoA )[0,1]; # output: # Another # Hacker
L*
In reply to Re^7: reading a JSON object -- sort and slicing AoA
by Discipulus
in thread reading a JSON object
by anautismobserver
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |