How to declare a variable globally so that it's visible for all perl modules? -


hi have perl script named main.pl. perl script calling 3 perl modules named sub1.pm, sub2.pm, , sub3.pm. sub.pm returning 3 hashes being used in sub2.pm , sub3.pm. passing hashes input parameter sub2 , sub3. instead there way can declare hashes globally visible these 2 perl modules?

when declare non-global variables, done putting "my" in front of it. i.e.:

my $local_variable = 4;

what wanting replace "my" "our" , make sure placed outside of subroutine. i.e.:

our $global_variable = 4;

if wish use in other modules, can add following:

use vars qw($global_variable);

now told how it, going tell not it. discouraged use global variables. should use local variables whenever can. reason because if ever working on larger project or project multiple coders, might find unknown errors variables might not equal expect them because changed elsewhere.


Comments