Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Answer: How do I do a natural sort on an array?

( #68394=categorized answer: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub byfile {
      my @a = split /(\d+)/, $a;
    ...
      }
      $res;
    }
    
  2. or download this
    53 7 119 53red
    red5 red6 red7 red67 red6.jpg red12.jpg
    green4.jpg
    blue2.jpg blue1000.jpg blue2.jpg58
    
  3. or download this
    7
    53
    ...
    red7
    red12.jpg
    red67
    
  4. or download this
     while (defined (my $A = shift @a) and defined (my $B = shift @b)) {
       $res = ($A =~ /\d/) ? $A <=> $B : $A cmp $B;
       return $res if $res;
     }
     return defined $A ? -1 : 1;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-12-28 07:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (179 votes), past polls