Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 ( #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? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2023-01-28 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?