Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by Dominus (Parson)
on Mar 30, 2001 at 19:19 UTC ( [id://68394]=note: 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://68394]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-26 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found