I don't really understand how scoping works in Perl modules. This doesn't print anything. I would like it if running a.pl printed 1
b.pm
$f=1;
a.pl
use b;
print $f
I don't really understand how scoping works in Perl modules. This doesn't print anything. I would like it if running a.pl printed 1
b.pm
$f=1;
a.pl
use b;
print $f
OK, you have a lot of misconceptions that we can best address by fixing your immediate problem and pointing you to good resources.
b.pm should be:
package b;
our $f = 1;
1;
a.pl should be
use b;
print $b::f
run the whole thing with perl -I. a.pl
Now go read perldoc
perlmod
very carefully.
Also read perldoc
strict
.
You should start off by reading about Perl modules in the manual: perldoc perlmod
at the commandline, or go to http://perldoc.perl.org/perlmod.html.
Short answer: Most probably because you're running this code on a case-insensitive file system, where asking for the module b
loads the built-in module B
. Your module is not getting loaded at all. If you rename b
, you get the result you expect.
The longer answer included lots of chiding for failing to observe even minimal good practice, and has been elided.