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

[ Natural Sort ]: Sorting a string with numbers

by zzspectrez (Hermit)
on Aug 12, 2005 at 23:52 UTC ( #483462=perlquestion: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @sorted = @list[
        map { unpack "N", substr($_,-4) }
        sort
    ...
            $key . pack "N", $_
        } 0..$#list
    ];
    
  2. or download this
    map {
        my $key = $list[$_];
        $key =~ s[(\d+)][ pack "N", $1 ]ge;
        $key . pack "N", $_
        } 0..$#list
    
  3. or download this
    my $key = $list[$_]
    $key =~ s[(\d+)][ pack "N", $1 ]ge;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://483462]
Approved by Joost
Front-paged by gmax
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2021-06-21 12:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (98 votes). Check out past polls.

    Notices?