Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2024-04-25 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found