I like the method of reading in key/value pairs from a file to populate a hash. After all, even the package global symbol tables are just elaborate hashes.

But if you really want to execute the variable declarations into existance you can use the Exporter module to help. See the documentation for that module, as well as our, and perlmod. This response has already been offered by others in this thread.

I just wanted to add that you can use the fully qualified variable name even without Exporter.pm, and it won't break strictures. For example, if you have a variable in package "Variables", and the var is named "$hello", you could access it from package main like this: print $Variables::hello, "\n";

Modules give namespace segregation, but you're still able to get at that namespace from the outside.


Dave


In reply to Re: global vars by davido
in thread global vars by rsiedl

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.