Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: sort, semi-numeric

by superpete (Beadle)
on Jan 02, 2003 at 18:12 UTC ( [id://223816]=note: print w/replies, xml ) Need Help??


in reply to sort, semi-numeric

Ok, I've reduced it to this :-)
sub sort_n { return map { $_->[0] } sort { my $l = @{$a->[1]} < @{$b->[1]} ? @{$a->[1]} : @{$b->[1]}; for (my $n=0; $n<$l; $n++) { my $A = $a->[1][$n]; my $B = $b->[1][$n]; my $tmp; if ($A =~ /\d/) { if ($B =~ /\d/) { $tmp = $A <=> $B; } else { $tmp = -1; } } else { if ($B =~ /\d/) { $tmp = 1; } else { $tmp = $A cmp $B; } } return $tmp if $tmp; } return @{$a->[1]} <=> @{$b->[1]}; } map { [ $_ , [ split( /(\d+)/, $_ ) ] ] } @_; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-28 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found