Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Custom Sort Array

by Laurent_R (Vicar)
on Aug 10, 2013 at 22:14 UTC ( #1048951=note: print w/ replies, xml ) Need Help??


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

I had not read carefully enough your post where you were also asking the files to be sorted according to the group of four digits after the date. It would be far better if you gave all your sorting rules from the outset.

This a new amendment to take this rule into account:

use strict; use warnings; my @files = map { $_->[0] } sort { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2] } map { [ $_, /\.(\d{12}\-\d{4})/, /.+?-(\d+)\..+$/ ] } <DAT +A>; print $_,$/ for @files; __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 abcd1_abc_123456.abc1a_A.201306290800-0900-0.gz abcd1_abc_123456.abc1a_A.201306290800-0900-1.gz abcd1_abc_123456.abc1a_A.201306290800-0900-10.gz abcd1_abc_123456.abc1a_A.201305290800-0900-11.gz abcd1_abc_123456.abc1a_A.201308290800-0900-2.gz abcd1_abc_123456.abc1a_A.201302290800-0900-3.gz abcd1_abc_123456.abc1a_A.201306290800-1000-1.gz abcd1_abc_123456.abc1a_A.201306290800-1000-10.gz abcd1_abc_123456.abc1a_A.201305290800-1000-11.gz abcd1_abc_123456.abc1a_A.201308290800-1000-2.gz abcd1_abc_123456.abc1a_A.201302290800-1000-3.gz

Output:

$ perl schwartz.pl abcd1_abc_123456.abc1a_A.201302290800-0900-3.gz abcd1_abc_123456.abc1a_A.201302290800-1000-3.gz abcd1_abc_123456.abc1a_A.201305290800-0900-11.gz abcd1_abc_123456.abc1a_A.201305290800-1000-11.gz abcd1_abc_123456.abc1a_A.201306290800-0900-0.gz abcd1_abc_123456.abc1a_A.201306290800-0900-1.gz abcd1_abc_123456.abc1a_A.201306290800-0900-10.gz abcd1_abc_123456.abc1a_A.201306290800-1000-1.gz abcd1_abc_123456.abc1a_A.201306290800-1000-10.gz 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-2.gz abcd1_abc_123456.abc1a_A.201307290800-0900-3.gz abcd1_abc_123456.abc1a_A.201307290800-0900-10.gz abcd1_abc_123456.abc1a_A.201307290800-0900-11.gz abcd1_abc_123456.abc1a_A.201308290800-0900-2.gz abcd1_abc_123456.abc1a_A.201308290800-1000-2.gz


Comment on Re^2: Custom Sort Array
Select or Download Code
Re^3: Custom Sort Array
by omegaweaponZ (Beadle) on Aug 13, 2013 at 13:02 UTC
    This is exactly what I was looking for, thank you!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (15)
As of 2014-07-29 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (220 votes), past polls