perlquestion
v_o_i_d
Hi monks,
I'm having this problem that I find very confusing, but which (I'm certain) has an easy answer which I can't find specifically addressed in the Q&A section or elsewhere.<p>
Basically I have a perl library (.pl) file. In it I declare a global variable <code>our $var</code> to be used in other modules via <code>require</code> etc. I also <code>use strict;</code> and <code>use warnings;</code>. In my perl module (.pm) this warning appears when I start using the 'global' variable: <code>Global symbol "$var" requires explicit package name</code>...<p>
When I remove the <code>use strict</code> this error does not appear, but I suspect that the problem remains. Am I right in believing the <code>$var</code> variable is being re-declared in the perl module or has it become local to the perl module file, and the declaration <code>our $var</code> in the perl library file is ignored?<p>
All I want to do is use the straight <code>$var</code> in other files and for <code>$var</code> to act like a true global variable.<p>
simple code mock-up:
<code>
#-----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?
#------------------
</code>