Any nice module to parse the file for me?

Well, given the other information you've added, it probably won't be so hard to parse the "glossary.pl" file on your own (the following has not been tested):

open(GLOSSARY, "glossary.pl") or die $!; my $word = ""; my $trans_hash = (); while (<GLOSSARY>) { if ( /\%(\w+)\s*=\s*/ ) { # look for start of hash definition $word = $1; } elsif ( $word ne "" ) { if ( /(\w+)\s*=>\s*([^,])/ ) { # find key => value assignment my ($lang, $trans) = ($1,$2); $trans_hash{$word}{$lang} = $trans; } elsif ( /^\s+\);/ ) { # watch for the end of the definition $word = ""; } } }
I'm basing this on the assumption that the style and syntax used in the glossary file are tightly constrained (and that the sample you showed is an accurate picture of the style being used). There's no guarantee that people adding to "glossary.pl" will always hew to the specific style shown in your post, but the fact that it's a shared resource makes it more likely that it will always have an easy, predictable format (at least, you could make it so without causing any of the dependent scripts to break.)

If the glossary file is likely to grow over time, you just need to make sure that it remains consistent with your parsing assumptions -- and maybe add a couple of error checks within or after the parsing loop above, to watch for signs of trouble (e.g., see if some words lack translations for some languages).

Since you're just reading the glossary.pl script as text data and using its contents to define keys and values for a hash array, this approach doesn't really pose any safety issues.

update: added a few comments to the code.


In reply to Re: Passing hash names in a file by graff
in thread Passing hash names in a file by heezy

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.