Why reopen the directory again to look for files matching $1-$2-$3? You are going to see those filenames eventually. Just populate the hash as you go, and let things fall into place. Use a 2nd layer of hashing with the date as the key, then you can sort on the date later as you need. You may want to consider doing a deep hash, with each part of the filename acting as a key at some level. You can still get sorted retrievals given the first 3 components as a key.
my %files; foreach (readdir(MYDIR)) { if (/([^-]+)-([^-]+)-([^-]+)-([^-]+)\.(pdf|html)/) { # using temp variables for illustrative purposes my ($name, $country, $language, $date) = ($1, $2, $3, $4); $files{$name}{$country}{$langauge}{$date} = $_; # alternatively for a less nested hash, you could do # $files{ join '-', $name, $country, $language }{$date} = $_; } } #### later sub get_files_by_key { my ($name, $country, $language) = @_; my $hash_ref = $files{$name}{$country}{$language}; # alternatively # my $hash_ref = $files{ join '-', $name, $country, $language }; # in any case, sorting them here is easy return map { $hash_ref->{$_} } sort keys %$hash_ref; } my @relevant_files = get_files_by_key('foo', 'us', 'en');
Obviously after reading this tale, you'll know that I'm unworthy to receive your assistance, but I beg to receive it.
Hey, this isn't the Internet Oracle. No need to supplicate!

ZOT,

blokhead


In reply to Re: Need help with efficient processing by blokhead
in thread Need help with efficient processing by cardozo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.