OK, building a press release index page. Customer wants it sorted by release date (though modification date by DCR may suffice). Is there a way to order readdir ? My current thought is to read each DCR, grab the release date from inside the DCR, drop it in a hash (with DCR name), sort the dates and process.That being said is there an easier way to read a folder pre-sorted say by modification date ?
my %hash1 = ( 20080101 => ["Harpo", "Chico", "Groucho", "Zeppo", "Gummo"], 20080214 => ["Sleepy", "Doc", "Grumpy", "Bashful"], 20080315 => ["Sneezy", "Happy", "Dopey"],);foreach my $k (sort keys %hash1) { print "$k\n\t" . join("\n\t", sort @{$hash1{$k}}) . "\n";}my %hash2 = ( 20080101 => [ {title => "Hippy dippy dee", author => "Some One"}, {title => "An apple climbed a tree", author => "Somebody Else"}, ], 20080214 => [ {title => "He lost his pants", author => "Another Person"}, {title => "And fell in a trance", author => "Some One"}, ], 20080315 => [ {title => "Hippy dippy dee - whoops", author => "Guess Who"}, ],);foreach my $k (sort keys %hash2) { print "$k\n"; foreach my $t (sort {$a->{title} cmp $b->{title}} @{$hash2{$k}}) { print "\t$t->{title} ($t->{author})\n"; }}
Hi Andy,another way would be to dirwalk the directories involved. Get Dates as per the real world logic and put into a hash.. using yyyymmdd_uniqueIdentifier format... Then sort the hash..I would prefer this approach rather than depending on OS commands as it will offer much more flexibility in changing and maintaining business logic
...read each DCR, grab the release date[...], drop it in a hash[...] sort and process. Is there a way to order readdir? is there an easier way to read a folder pre-sorted?
Are you parsing the DCRs for any other information? Like title, author, etc.?If so - then the hash idea is reasonable because you're going to have to pay the price for reading in and parsing each file anyway - so there's no need to add to the price by running a system, rather than builtin, command (as was suggested) -- and this way if someone modifies something to fix a typo or some such, it remains sorted by its specified release date rather than by the modification timestamp on the file.
Your brother needs a life. Must run in the family.
Yes I am using iw_load_dcr later down the road. My current approach is@files = map {dir...}foreach @filesiw_load_dcrbuild the HTML for thatYou are suggesting I read & parse all DCRs into a hash, sort by date, and generate the HTML. Seems faster to run the TPL but certainly more complicated. I use the iwpt tags instead of creating a Perl TPL. I will keep it as such initially & see if I really need to change.ThanksAndy
It's a reply like this one: "I can read to hash, sort and process. Is there another way?" - "Sure is! Read to hash, sort and process".Why didn't you read the thread before chiming in? Here is the excerpt from the very first one:Do you have something to contribute to what has been really asked?