Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: sort, semi-numeric

by superpete (Beadle)
on Jan 02, 2003 at 18:12 UTC ( #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
Node Status?
node history
Node Type: note [id://223816]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2020-12-02 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (26 votes). Check out past polls.

    Notices?