Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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 lurking in the Monastery: (4)
As of 2021-05-12 08:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (125 votes). Check out past polls.

    Notices?