> *) Lexical variables belong to the package they are declared in.  (Or,
> if not declared, the package to which they belong can be inferred.)

Well, lexical variables don't belong to any package in Perl. They're not
in the symbol table, hence why others can't mess with them. That's why a
"my $var" is different from a "$pkg::var". The latter gets in the symbol
table, the former doesn't.

Personally, I like your other idea much better - make lexicals the true
default. Dynamics actually do have some advantages. For one thing, you
can't do this with lexicals:

   use MyPackage;
   $MyPackage::DEBUG = 1;

This would be a hard (read: impossible) thing for me to give up.

However, make lexicals the default so that MyPackage would have to look
like this:

   package MyPackage;
   
   # my is redundant since lexicals are default
   my($internal1, $internal2) = ('value1', 'value2');

   # have to use your to give this variable to other packages
   your $DEBUG = 0;      # $MyPackage::DEBUG now dynamic

I think something like this is a good idea. It's more intuitive too -
hide your variables in your package unless you *want* to give others
access to them. 

If you're going to write an RFC on this, cool. Otherwise I will, just to
keep it interesting. In particular I've "fallen in love" with the
"your()" keyword. :-)

-Nate

Here's a great p5p message on Perl lexicals vs. globals/dynamics:
http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-05/msg00839.html

Reply via email to