Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by johngg (Canon)
on Dec 02, 2020 at 00:17 UTC ( [id://11124491]=note: print w/replies, xml ) Need Help??


in reply to How can I sort my array numerically on part of the string?

A GRT solution, in the interests of TIMTOWTDI.

johngg@abouriou:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' my @list = do { no warnings qw{ qw }; qw{ 1,cat 2,dog, 22,mouse frog 11,eel 001,elk horse 002,bear 13,min +k }; }; say for map { unpack q{x54A50} } sort map { pack q{NA50A50}, ( m{^(\d+),(\S+)} ? ( $1, $2 ) : ( 0, q{} ) +), $_ } @list;' frog horse 1,cat 001,elk 002,bear 2,dog, 11,eel 13,mink 22,mouse

I hope this is of interest.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 01:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found