jey has asked for the wisdom of the Perl Monks concerning the following question:
Dear fellow monks,
I would like to know if there is a way of accessing a scalar defined in a program from a module that this program uses.
Let's imagine, I have a program:
#!/usr/bin/perl -w use strict; use My::Module; my $foo = "some string" my $bar = Somefunction();
and a module
package My::Module; our @EXPORT = qw/Somefunction/; use Exporter; our @ISA = qw/Exporter/; sub Somefunction { # do something; }
I want to use the information contained in $foo in the module. I know, I could pass $foo as an argument, but I have a lot of functions in my module and I would like to avoid this redundant information.
I have already tried things like $main::foo, but it does not work (maybe I am missing something, or it might even be a completely stupid idea, I must say I have no clue).
Could someone please just tell me if there is a smart way of accessing a variable in a subroutine (the shorter the better).
Thanks in advance,
Update: Change My/Module to My::Module
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing a Scalar from a module
by gaal (Parson) on Dec 17, 2004 at 22:17 UTC | |
|
Re: Accessing a Scalar from a module
by jZed (Prior) on Dec 17, 2004 at 19:48 UTC | |
|
Re: Accessing a Scalar from a module
by graff (Chancellor) on Dec 18, 2004 at 06:53 UTC |