[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Package shadowing



On 12 Feb 2001, at 8:44, Tim Ayers wrote:

> I am hoping someone will explain why the following program produces
> the warning
> 
>   "my" variable $a masks earlier declaration in same scope 
>   at /home/tayers/pkg.pl line 11.
>   package foo;
> 
>   my $a = 'foo';
> 
>   sub foo { "foo::a=$a" }

I'm not sure this is a 'fun' topic, but the answer is that 'my' variables 
are *NOT* packagized [indeed, AFAIK they don't go into any symbol table 
at all].  They're just lexically cross-referenced.

For example:

$ perl -e 'package f; my $a = 4; $f::a = 6; warn $a'
4 at -e line 1.

  /Bernie\

-- 
Bernie Cosell                     Fantasy Farm Fibers
mailto:bernie@fantasyfarm.com     Pearisburg, VA
    -->  Too many people, too few sheep  <--          

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe