hacker has asked for the wisdom of the Perl Monks concerning the following question:
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:
In each of these languages, I build a structure that looks like:my @langs = ('en', 'de', 'fr', 'it', 'gr', '...'); my @projects = ('dogs', 'cats', 'birds', 'horses'); my @targets = ('images', 'data', 'links', 'other');
Within each of those projects, I fetch the data for them:endogs, encats, enbirds, enhorses dedogs, decats, debirds, dehorses frdogs, frcats, frbirds, frhorses itdogs, itcats, itbirds, ithorses grdogs, grcats, grbirds, grhorses
The way I'm doing this is very "array-based":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
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Dating a Structure
by punch_card_don (Curate) on Jul 01, 2007 at 04:21 UTC | |
by naikonta (Curate) on Jul 01, 2007 at 13:49 UTC | |
Re: Dating a Structure
by toma (Vicar) on Jul 01, 2007 at 19:01 UTC | |
Re: Dating a Structure
by FunkyMonk (Chancellor) on Jul 01, 2007 at 22:08 UTC | |
re: Embiggen
by bibliophile (Prior) on Jul 01, 2007 at 16:11 UTC |