There's an awesome and often unused tool that comes with perldoc that will just tell you about particular Perl keywords. Using "perldoc -q my" will tell you that,
So, enclosing your variable declarations inside of different blocks resolves the problem. Here's a more involved example:A "my" declares the listed variables to be local (lexically) to the e +nclosing block...
#!/usr/bin/env perl + + use strict; use warnings; package Foo; { my $package = __PACKAGE__; sub new { return bless {'PACKAGE'=>$package} } } package Bar; { my $package = __PACKAGE__; sub new { return bless {'PACKAGE'=>$package} } } package main; my $foo = Foo->new; my $bar = Bar->new; print $foo->{'PACKAGE'}; print qq|\n\n|; print $bar->{'PACKAGE'};
Celebrate Intellectual Diversity
In reply to Re: my $var masked across package scope?
by InfiniteSilence
in thread my $var masked across package scope?
by QM
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |