%MY:: manipulates my lexical pad.  If, to resolve a variable, I have to 
search backwards through multiple pads (that's a metaphysical search, so as 
to not dictate a physical search as the only behavior), that's a different 
beastie.

Consider it like, oh, PATH and executables:
`perl` will search PATH and execute the first perl found, but 'rm perl' will 
not.  It would only remove a perl in my current scope..., er, directory.

On Thursday 06 September 2001 08:28 am, Dave Mitchell wrote:
> > > my $x = 100;
> > > {
> > >     my $x = (%MY::{'$x'} = \200, $x+1);
> > >     print "inner=$x, ";
> > > }
> > > print "outer=$x";
> > >
> > > I'm guessing this prints inner=201, outer=200

Oops, I may have been wrong.  This might give you {some random number}, 100,
depending on how the reference is handled.

What you are, in essence, doing, is creating a lexical $x in my current 
scope, and setting that to be a reference to 200.  You're then taking that 
newly created lexical $x, adding 1 to it (which currently is adding one to 
the address of the constant, but whatever), and that is being stored in, 
effectively, itself.

> >
>
> I was just trying to confirm whether similar semantics apply to the use of
> %MY:: - ie when used where a lexical has been defined but not yet
> introduced, does %MY{'$x'} pick up the inner or outer lex?
>
> I especially wanted to confirm whether delete %MY{'$x'} will delete the
> outer $x because the inner one isn't yet quite in scope.

The delete should be no-oppish, as the lexical variable doesn't exists yet 
in the current lexical scope.  If you want to mess with your parent's scope, 
you have to mess with it directly, not indirectly.

-- 
Bryan C. Warnock
[EMAIL PROTECTED]

Reply via email to