Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, I am trying to sort an array of arrays, but i am stuck. I have red some sources on the internet, but it is not helping me enough. I hope someone can tell me why i am failing. I am trying to sort this array on the second element. Here is the code:
@ar = ([1,12],[8,3],[4,57],[22,5]); @sort = sort{$a[1]<=>$b[1]}@ar; foreach (@sort){ print "@$_\n";}
The desired output is: 8,3 22,5 1,12 4,57. But all i'm getting is the same sorting as i started with. Tx in advance.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: sorting array of arrays
by hippo (Bishop) on Jan 18, 2020 at 17:27 UTC | |
by Anonymous Monk on Jan 18, 2020 at 17:43 UTC | |
Re: sorting array of arrays
by AnomalousMonk (Archbishop) on Jan 18, 2020 at 20:13 UTC | |
by fanasy (Sexton) on Jan 20, 2020 at 03:33 UTC | |
by AnomalousMonk (Archbishop) on Jan 20, 2020 at 04:43 UTC |
Back to
Seekers of Perl Wisdom