Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does scoping work in Perl modules?

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
like image 408
Mike Avatar asked May 23 '26 11:05

Mike


2 Answers

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 perldocperlmod very carefully.

Also read perldocstrict.

like image 158
David M Avatar answered May 26 '26 09:05

David M


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.

like image 30
Ether Avatar answered May 26 '26 07:05

Ether



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!