Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by tybalt89 (Monsignor)
on Dec 01, 2020 at 21:15 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11124483]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-25 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found