in reply to Sorting an array of strings by number
@lines = ( q{23.40:hello:this:is:a:line}, q{123.38:this:is:another:line}, q{7.32895:yet:another:line}, ); @sorted = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ (split(/:/,$_))[0], $_ ] }@lines;
Of course, if you're going to split things anyhow, it might make just as much sense to go ahead and split the whole line and just use that.
@split = sort { $a->[0] <=> $b->[0] } map { [ split /:/ ] } @lines;
|
|---|