Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: (turnstep) Sorting on Section Numbers

by turnstep (Parson)
on Jul 28, 2000 at 22:05 UTC ( #24943=note: print w/ replies, xml ) Need Help??


in reply to Sorting on Section Numbers

Here is my version. I *think* it should work for all cases. I'll break it down if anyone is curious.

@sorted = map { $_->[0] } sort { $x=1; while (defined $a->[1][$x]) { defined $b->[1][$x] or return -1; if ($x%2) { ## Strict numeric comparison return 1 if $a->[1][$x] > $b->[1][$x]; return -1 if $a->[1][$x] < $b->[1][$x]; } else { ## Non-numeric comparison return 1 if $a->[1][$x] gt $b->[1][$x]; return -1 if $a->[1][$x] lt $b->[1][$x]; } $x++; } return defined $b->[1][$x] ? 1 : 0; } map { [$_, [split(/(\d+)/, $_)]] } @unsorted;


Comment on Re: (turnstep) Sorting on Section Numbers
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://24943]
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: (7)
As of 2014-11-27 08:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (181 votes), past polls