Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: How can I sort my array numerically on part of the string?

by tybalt89 (Prior)
on Dec 01, 2020 at 21:15 UTC ( #11124483=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/perl
    
    ...
    my @list = ( '1,cat', '2,dog', '22,mouse', '11,eel', '001,elk', '13,mi
    +nk');
    
    print join "\n", sort { $a=~s/,.+//r <=> $b =~ s/,.+//r  } @list;
    
  2. or download this
    1,cat
    001,elk
    ...
    11,eel
    13,mink
    22,mouse
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11124483]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2021-04-19 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?