Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Custom Sort Array

by 2teez (Priest)
on Aug 10, 2013 at 20:42 UTC ( #1048943=note: print w/replies, xml ) Need Help??


in reply to Re: Custom Sort Array
in thread Custom Sort Array

Hi,
arkturuz, will even work if the regex matches the values to be sorted like this:

chomp(my @files = <DATA>); ## added sub by_id { # extract numbers my ($A) = $a =~ /.+?-(\d+)\..+$/; # changed my ($B) = $b =~ /.+?-(\d+)\..+$/; # changed # return comparison return $A <=> $B; } for my $f (sort by_id @files) { print $f,$/; } __DATA__ abcd1_abc_123456.abc1a_A.201307290800-0900-0.gz abcd1_abc_123456.abc1a_A.201307290800-0900-1.gz abcd1_abc_123456.abc1a_A.201307290800-0900-10.gz abcd1_abc_123456.abc1a_A.201307290800-0900-11.gz abcd1_abc_123456.abc1a_A.201307290800-0900-2.gz abcd1_abc_123456.abc1a_A.201307290800-0900-3.gz

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048943]
help
Chatterbox?
[Corion]: Whoa! I haven't invoked Crunchy today! But thanks to Crunchy, it's Friday! ;)
[Corion]: A good morning to everybody ;)
[Discipulus]: regular as always.. good morning Corion
[Corion]: Hi Discipulus ;) A good morning to you :)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2017-01-20 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (173 votes). Check out past polls.