Perl numerical sorting: how to ignore leading alpha character [migrated]
- by Luke Sheppard
I have a 1,660 row array like this:
...
H00504
H00085
H00181
H00500
H00103
H00007
H00890
H08793
H94316
H00217
...
And the leading character never changes. It is always "H" then five digits. But when I do what I believe is a numerical sort in Perl, I'm getting strange results. Some segments are sorted in order, but then a different segment starts up. Here is a segment after sorting:
...
H01578
H01579
H01580
H01581
H01582
H01583
H01584
H00536
H00537
H00538
H01585
H01586
H01587
H01588
H01589
H01590
...
What I'm trying is this:
my @sorted_array = sort {$a <=> $b} @raw_array;
But obviously it is not working. Anyone know why?