Hey, I am trying to make my module aware of version number that would not need to be hardcoded in the module but instead initialized in a form of env variable in the program that actually calls all other perl scripts that make use of this module:
$ENV{"VER"} = "3.0";
In the module I planned to give a life to a global variable on the top of the module and use it across all subs/methods as follows:
my $ver_dir = "/opt/SAT/" . $ENV{"VER"};
$ENV{"VER"} however is undef at this stage yet. I would need to actually use it in subs/methods wherever I need to resolve path. It does seem to work in this way although that would cause me some real pain. Other way I thought of was to declare $ver_dir, as global var, as follows:
my $ver_dir = set_ver_dir();
wherea set_root_dir would be:
sub set_ver_dir { my $path = $FindBin::Bin; $path =~ /\opt\/SAT\/(\d*\.\d*)\//; my $ver = $1; return "/opt/SAT" . $ver }
Though such trick for making global vars within a module a result of one of module's sub does not seem to work. Any suggestions? Mind, tha I would NOT like to have it hardcoded in the module. Nor use any symlinks such us /opt/SAT/live or /opt/SAT/current that would point to the correct version on the file system.

Thank you.

In reply to dynamiclly assigning values to global variables in modules by bazi

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.