How does browsing work in Perl modules?

I really don't understand how scoping works in Perl modules. It doesn't print anything. I would like it to print 1 when running a.pl

b.pm

$f=1;

      

a.pl

use b;

print $f

      

+2


a source to share


3 answers


Okay, you have a lot of misconceptions that we can best solve by identifying your immediate problem and pointing out good resources.

b.pm should be:

package b;
our $f = 1;
1;

      

a.pl should be



use b;
print $b::f

      

do it all with perl -I. a.pl

Now read carefully perldoc

perlmod

.

Also read perldoc

strict

.

+11


a source


You should start by reading the Perl modules in the manual: perldoc perlmod

on the command line, or go to http://perldoc.perl.org/perlmod.html .



+3


a source


Short answer: most likely because you are using this code on a caseless filesystem where the module b

is requested loads the inline module b

. Your module is not loading at all. If you rename b

, you get the expected result.

The longer answer included many exercises for not following even minimal good practice and being denied.

+2


a source







All Articles