in reply to Re: Sorting a File which contains numbers
in thread Sorting a File which contains numbers
perl -le '@arr = (2, 17, 8, 5, 26); print for sort @arr;'
produces
17 2 26 5 8
whereas
perl -le '@arr = (2, 17, 8, 5, 26); print for sort {$a <=> $b} @arr;'
does a numerical sort and produces
2 5 8 17 26
To sort descending numerically change the anonymous sort routine to {$b <=> $a} rather than using reverse.
Cheers,
JohnGG
|
|---|