Hi, I have been searching the web for some advice on how to have persistent variables or how can we access a variable defined with our in a perl program file(.pl or main package one can say) across other modules.

I have read so many posts and articles but one or the other explains how to share global variables among packages( using exporter most of the time and somewhere through perl aliasing feature), but no one encounters a scenario in which a global variable from the main::package or say main.pl is required in some module.

To explain it or be specific in explaining my particular scenario let say:

#!/usr/bin/perl # main.pl use warnings; use strict; require "functions.pl"; our ($glbA, $glbB); $glbA = "Main_GlobalA"; $glbB = "Main_GlobalB"; procedureA(); procedureB();
#!usr/bin/perl # functions.pl use warnings; use strict; sub procedureA { print $glbA; } sub procedureB { print $glbB; } 1;
I have been stuck on this issue for a week now. Any sort of suggestion or correction in my approach would be of great help! Waiting for a prompt reply


In reply to How to access main package global vars in modules by codewalker82

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.