Thanks to the patient mentoring of Anno, bart, and clinton, I'm making this post to embiggen my Perl skills.

I've got a project that I'm building to mirror an enormous amount of data in several dozen languages. Right now I have 3 separate arrays:

my @langs = ('en', 'de', 'fr', 'it', 'gr', '...'); my @projects = ('dogs', 'cats', 'birds', 'horses'); my @targets = ('images', 'data', 'links', 'other');
In each of these languages, I build a structure that looks like:
endogs, encats, enbirds, enhorses dedogs, decats, debirds, dehorses frdogs, frcats, frbirds, frhorses itdogs, itcats, itbirds, ithorses grdogs, grcats, grbirds, grhorses
Within each of those projects, I fetch the data for them:
endogs/images.tar.bz2 endogs/data.tar.bz2 endogs/links.tar.bz2 endogs/other.tar.bz2 dedogs/images.tar.bz2 dedogs/data.tar.bz2 dedogs/links.tar.bz2 dedogs/other.tar.bz2 [...] encats/images.tar.bz2 encats/data.tar.bz2 encats/links.tar.bz2 encats/other.tar.bz2 decats/images.tar.bz2 decats/data.tar.bz2 decats/links.tar.bz2 decats/other.tar.bz2
The way I'm doing this is very "array-based":
foreach my $lang (@langs) { foreach my $project (@projects) { mkpath ("$project/$lang"); foreach my $target (@targets) { my $backup = $backup_file; my $output = $output_save_file; print "Mirroring $project ($lang) now...\n"; # Other stuff happens here } } }

I've always had trouble grokking hashes in Perl, many people know that... but it looks like I have to bite the bullet here and dive into an HoHoA to create this structure.

My question is... can I create a "completely anonymous hash", which can be built dynamically from the values in each of the arrays above? I'd actually like to add more granular detail here, without adding more and more arrays (further increasing that nesting)... something like:

'it' => 'Italian' { ... }, 'es' => 'Spanish' { ... }, ...

The goal is to be able to fetch each of the @targets within each of the @projects, for each @lang supported. If I want to back up another set of targets in another language, I should just be able to add another language to the list and have it inherit the rest of the members of the "anonymous hash" (if I'm using the vernacular correctly).

Is this possible? Is there another way to represent this structure without more levels of array nesting, and without duplicating manually-typed entries in a growing sub?


In reply to Dating a Structure by hacker

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.