in reply to Re: how do I sort numerically on sections of data that is alphanumeric
in thread how do I sort numerically on sections of data that is alphanumeric
my @sorted_array = sort { # compare the second numbers substr($a, 12, 9) <=> substr($b, 12, 9) # compare the third numbers or substr($a, 22, 12) <=> substr($b, 22, 12) } @array;
That is, for each pair of lines that's being compared, use substr to get the fixed fields, and compare them numerically. The first <=> will return non-0 if the numbers in the second field are different, and the third field won't be compared in that case (because of the or).
|
|---|