Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2016-06-25 08:16 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (323 votes). Check out past polls.