Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^5: Custom Sort Array

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


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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048947]
help
Chatterbox?
[1nickt]: virtualsue Have you made them tea yet today? (And do you serve Digestives with it?)
[virtualsue]: Lotus biscuits
[Discipulus]: mornign nuns and monks!
[1nickt]: Woah you can get Krispy Kreme doughnut-Lotus Biscoff hybrids!
[1nickt]: Biscuit technology has evolved since I left the UK, obviously.
[virtualsue]: we have a jar of the spread: https://www. sainsburys.co.uk/ webapp/wcs/stores/ servlet/gb/ groceries/lotus- caram-spread- smooth-400g?langId =44&storeId=10151& krypto=VEjeoyIieB6 2oiiKUSbS %2Foxs9BpfJxZ95MW6 y6NOiYDYlKgl6SghbS BZf7CU5b6QA00pmYz7 XmfTYYKpoIiUivBBOR y6MI
[virtualsue]: yuk url https://www.amazon .co.uk/Lotus- Original- Caramelised-Spread -Smooth/dp/ B002LA793I

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2017-11-20 11:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (286 votes). Check out past polls.

    Notices?