in reply to Re^2: Custom Sort Array
in thread Custom Sort Array
...There's a 1, so the 1 shows up before the 10, and 11, then the 2 shows up. This goes well beyond just 1, however. Logs can go as far as 99, so I need a solution that will organize them up to the point of this final -##.gz in the name from 0-99+ in numeric order.
you will have:use strict; use warnings; my @files = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, /.+?-(\d+)\..+$/ ] } <DATA>; 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.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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Custom Sort Array
by omegaweaponZ (Beadle) on Aug 10, 2013 at 20:41 UTC | |
by AnomalousMonk (Archbishop) on Aug 10, 2013 at 21:39 UTC | |
by 2teez (Vicar) on Aug 10, 2013 at 21:28 UTC |