develooper Front page | perl.perl6.language | Postings from September 2001

Re: What's up with %MY?

Thread Previous | Thread Next
From:
Bryan C . Warnock
Date:
September 6, 2001 05:17
Subject:
Re: What's up with %MY?
Message ID:
01090608132409.32512@wakko.idiocity.nut
On Thursday 06 September 2001 06:16 am, Dave Mitchell wrote:
> One further worry of mine concerns the action of %MY:: on unintroduced
> variables (especially the action of delete).
>
> 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

Perhaps I missed something, but %MY:: refers to my lexical scope, and not my 
parents, correct?

Why isn't this inner=201, outer=100?

>
> As for
>
> my $x = 50;
> {
>     my $x = 100;
>     {
> 	my $x = (delete %MY::{'$x'}, $x+1);
> 	print "inner=$x, ";
>     }
>     print "middle=$x, ";
> }
> print "outer=$x";
>
> If delete 'reexposes' an outer version of that variable, then I'd
> speculate the output would be
>
> inner=51, middle=50, outer=50

Again, I though that %MY:: referred to my current scope, in which case the 
delete doesn't do anything.  That would make it 101, 100, 50.

Is my understanding incorrect?

-- 
Bryan C. Warnock
bwarnock@capita.com

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About