Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: how do I sort numerically on sections of data that is alphanumeric

by Brovnik (Hermit)
on Jun 26, 2001 at 23:44 UTC ( #91729=note: print w/ replies, xml ) Need Help??


in reply to how do I sort numerically on sections of data that is alphanumeric

Or, there is the Schwartzian Transform.

# array is in @sorted my @sorted = map {$_->[0] } sort {$a->[2] <=> $b->[2] or substr($a->[3],1) <=> substr($b->[3],1)} map {[$_,split)] } @unsorted;
Note: If the 'A' in column 3 is always 'A' and the columns are null padded, then you don't need the substr and can use
sort { $a->[2] <=> $b->[2] or $a->[3] cmp $b->[3] }
Note the switch to cmp since this now a string.
--
Brovnik


Comment on Re: how do I sort numerically on sections of data that is alphanumeric
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://91729]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2015-07-08 03:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls