in reply to Sorting an array of strings by number
You need to use a numeric sort (the default is alphabetic). Provided the numbers are at the start of the line you can just do this:
my @data = <DATA>; my @alpha_sort = sort { $a cmp $b } @data; my @numeric_sort = sort { $a <=> $b } @data; print "Alpha sort\n@alpha_sort\n"; print "Numeric sort\n@numeric_sort\n"; __DATA__ 123.45Hello 32.2World 1.5Just 288.2Another 288.3Perl 288.4Hacker
If you have more complex requirements then a Schwartzian transform will be in order.
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|