rvosa has asked for the wisdom of the Perl Monks concerning the following question:
I want these sorted numerically on the second dimension, the numerical values. What I'm looking for is:@AoA = ( [ "n1", "34" ], [ "n3", "14" ], [ "n2", "1" ], [ "n4", "5" ], );
Naively, I figured something like the following would work:@sorted = ( [ "n2", "1" ], [ "n4", "5" ], [ "n3", "14" ], [ "n1", "34" ], );
But I seem to get nothing but emptiness... so how is this done the right way?@sorted = map { [ $_[0], $_[1] ] } sort { $a->[1] <=> $b->[1] } map { +[ $_[0], $_[1] ] } @AoA;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Do the Schwartzian boogy!
by PodMaster (Abbot) on May 30, 2005 at 09:53 UTC | |
by rvosa (Curate) on May 30, 2005 at 10:02 UTC | |
|
Re: Do the Schwartzian boogy!
by salva (Canon) on May 30, 2005 at 10:10 UTC | |
by wazoox (Prior) on May 30, 2005 at 10:17 UTC | |
by salva (Canon) on May 30, 2005 at 11:07 UTC | |
|
Re: Do the Schwartzian boogy!
by polettix (Vicar) on May 30, 2005 at 10:02 UTC |