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

We might be looking at it differently (me being the novice!), but doing this I organize it, 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. That is critical or the logs will be useless
foreach (@files) { my $file = $_; my @newfiles = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, /.+?-(\d+)\..+$/ ] } @files; print $_,$/ for @newfiles; outputs for example: abcd1_abc_123456.abc1a_A.201307282200-2300-9.gz abcd1_abc_123456.abc1a_A.201307282300-2400-9.gz abcd1_abc_123456.abc1a_A.201307272100-2200-10.gz abcd1_abc_123456.abc1a_A.201307281900-2000-10.gz I need it to output like this: 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 ..etc.. 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 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 ..etc.. 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

Replies are listed 'Best First'.
Re^5: Custom Sort Array
by AnomalousMonk (Archbishop) on Aug 10, 2013 at 21:39 UTC

    You have received some good answers based on the info you have given. Unfortunately, that info has been incomplete or contradictory and has caused considerable wasted motion (and a bit of evident frustration) on the part of your fellow monks. What we'd like to know is something like this: for a typical string defined thusly
        abcd1_abc_123456.abc1a_A.201307282200-2300-12.gz
                      field A ---^^^^^^^^^^^^      ^^--- field B
                 fixed width?                            variable width!
                fixed offset?                            fixed offset?
    sort first (numerically? ascending?) by field X, then sort (numerically? ascending?) by field Y.

    A mind is a terrible thing to waste.   Please think before you post!

Re^5: Custom Sort Array
by 2teez (Vicar) on Aug 10, 2013 at 21:28 UTC

    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:
    my @files = map{$_->[0]} sort{ $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] || $a->[3] <=> $b->[3] } map{[$_,/.+?_A\.(.+?)-(.+?)-(\d+)\..+$/]}<DATA>;
    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