v_o_i_d has asked for the wisdom of the Perl Monks concerning the following question:
Basically I have a perl library (.pl) file. In it I declare a global variable our $var to be used in other modules via require etc. I also use strict; and use warnings;. In my perl module (.pm) this warning appears when I start using the 'global' variable: Global symbol "$var" requires explicit package name...
When I remove the use strict this error does not appear, but I suspect that the problem remains. Am I right in believing the $var variable is being re-declared in the perl module or has it become local to the perl module file, and the declaration our $var in the perl library file is ignored?
All I want to do is use the straight $var in other files and for $var to act like a true global variable.
simple code mock-up:
#-----file1.pl----- use strict; use warnings; our $var = 1; #------------------ #-----file2.pm----- use strict; use warnings; require 'file1.pl'; $var = 2; # <-- This doesn't work, but it is supposed to be global, + right? #------------------