Hi,
...We might be looking at it differently...
No, we are not, worked within the premises of the condition you gave initially.
... however, the dates will change, so it seems to only group by the last number, not by the date as well. See how all 9's and all 10's, etc, will be grouped, regardless of the prior date....
Because you are changing the rule of the game ....
Moreover, the output example you gave don't tally with the expected output. However, the solution, I gave initially can still be twisted a bit to make your expectation work.
How? match the relevant values, then sort by them in any way you wanted.
See below:
use strict;
use warnings;
my @files = map{$_->[0]}
my @files = map{$_->[0]}
sort{
$a->[1] <=> $b->[1]
||
$a->[2] <=> $b->[2]
||
$a->[3] <=> $b->[3]
}
map{[$_,/.+?_A\.(.+?)-(.+?)-(\d+)\..+$/]}<DATA>;
print $_,$/ for @files;
__DATA__
abcd1_abc_123456.abc1a_A.201307282200-2300-1.gz
abcd1_abc_123456.abc1a_A.201307282200-2300-2.gz
abcd1_abc_123456.abc1a_A.201307282200-2300-3.gz
abcd1_abc_123456.abc1a_A.201307282200-2300-4.gz
abcd1_abc_123456.abc1a_A.201307282300-2400-1.gz
abcd1_abc_123456.abc1a_A.201307282300-2400-2.gz
abcd1_abc_123456.abc1a_A.201307282300-2400-3.gz
abcd1_abc_123456.abc1a_A.201307282300-2400-4.gz
abcd1_abc_123456.abc1a_A.201307282300-2400-5.gz
abcd1_abc_123456.abc1a_A.201307282300-2400-10.gz
abcd1_abc_123456.abc1a_A.201307282300-2400-11.gz
abcd1_abc_123456.abc1a_A.201307282300-2400-12.gz
abcd1_abc_123456.abc1a_A.201307282200-2300-10.gz
abcd1_abc_123456.abc1a_A.201307282200-2300-11.gz
abcd1_abc_123456.abc1a_A.201307282200-2300-12.gz
NOTE:
Please bear in mind that, I modified the
DATA used. Since, I don't know how your data is formed exactly and how you want them sorted.
lastly, please remove, this
foreach (@files) {
my $file = $_;
from your code.
Hope this helps.
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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.