Confused? Put in temporary arrays, just to see what we're doing.@sorted = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ length $_, $_ ] } @strings;
create a temporary array of anonymous arrays
(0: length of the string, 1: the string)
sort by length@temp = map { [ length $_, $_ ] } @strings;
grab just the strings and put them in @sorted@temp = sort { $a->[0] <=> $b->[0] };
Knowing the context of certain operationsand being able to chain them together is crucial to a deep and idiomatic understanding of Perl.@sorted = map { $_->[1] } @temp;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Efficient sorting using the Schwartzian Transform
by I0 (Priest) on Jan 02, 2001 at 18:06 UTC |