Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: sorting number

by Tux (Canon)
on Apr 09, 2019 at 06:22 UTC ( [id://1232328]=note: print w/replies, xml ) Need Help??


in reply to sorting number

my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [ $_, s/^CORE//r =~ s/(\d+)/sprintf "%06d", $1/ger ] } @aa;

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: sorting number
by AnomalousMonk (Archbishop) on Apr 09, 2019 at 07:17 UTC
    [ $_, s/^CAORE//r =~ s/(\d+)/sprintf "%06d", $1/ger ] } @aa;

    I don't understand the  s/^CAORE//r part of this expression. It seems to be doing nothing, and the sorted output is the same without it:

    c:\@Work\Perl\monks>perl -wMstrict -le "my @aa = qw( CORE1 CORE12 CORE8 CORE233 COREA11 COREA12 COREA130 COREA115 ); my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [ $_, s/(\d+)/sprintf \"%06d\", $1/ger ] } @aa; print qq{@sorted}; " CORE1 CORE8 CORE12 CORE233 COREA11 COREA12 COREA115 COREA130
    Can you please elaborate?


    Give a man a fish:  <%-{-{-{-<

      1. It is a typo (CAORE instead of CORE) - answer edited
      2. Not required indeed

    Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-19 10:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found