|
|
| "be consistent" | |
| PerlMonks |
Share Variable in Script with a Moduleby DanielSpaniel (Scribe) |
| on Oct 04, 2013 at 21:58 UTC ( [id://1056943]=perlquestion: print w/replies, xml ) | Need Help?? |
|
DanielSpaniel has asked for the wisdom of the Perl Monks concerning the following question: I have a script (we'll call it test.pl), which "use"s a module (we'll call it my_module.pm). test.pl is kicked off with some varying arguments provided to it (i.e. different arguments each time it's run), and I would like to share one of these variables with my_module.pm, so that when my_module.pm first gets loaded it'll do something different according to the variable's value. So, examples of what I have are below:
test.pl looks like this:
In this test.pl, just for an example, I'm just providing a static argument, but in reality it's a varying value. Nevertheless, what I'm anticipating is that test.pl will "use" my_module, and pass in "xyz" and then the module will print the "Yep, I'm in here" message, followed by "xyz" when it gets to my_sub, which is called when my_module is loaded. However, I guess I must be misunderstanding something because the "Yep, I'm in here" message never gets printed, and the variable is empty when it gets to my_sub. Thus, I guess the import sub is never being called, but I thought that by default an import sub is always called, if it exists, when "use"ing a module. Noting that I don't want to share a variable from the module to the script, but vice-versa, if anyone could shed some light, or suggest a better method, then I'd be grateful. Thanks!
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||||||||||