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

[FWP] Package shadowing



Hi all,

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.

----------------------- pkg.pl ----------------------------------
  #!/usr/bin/perl -w

  package foo;

  my $a = 'foo';

  sub foo { "foo::a=$a" }

  package bar;

  my $a = 'bar';

  sub bar { "bar::a=$a" }

  package main;

  print foo::foo(), "   ", bar::bar(), "\n";
----------------------- pkg.pl ----------------------------------

The $foo::a and $bar::a variables are not available outside their
respective package as far as I can tell. I assume the compiler keeps
track of package switches. Why does it think I'm doing something
worrisome? Thanks and

Hope you have a very nice day, :-)
Tim Ayers (tayers@bridge.com)



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