develooper Front page | perl.perl6.language | Postings from July 2002

Re: What's MY.line?

Thread Previous | Thread Next
From:
Ashley Winters
Date:
July 11, 2002 13:09
Subject:
Re: What's MY.line?
Message ID:
200207111308.44937.qaqortog@nwlink.com
On Thursday 11 July 2002 11:47 am, Chip Salzenberg wrote:
> According to Dan Sugalski:
> > At 9:50 PM -0400 7/9/02, Chip Salzenberg wrote:
> > >    3a. If so, how can one distinguish among the e.g. many C<my $foo>
> > >        variables declared within the current function?
> >
> > One pad per block, rather than per sub.
>
> I just remembered why I thought that woundn't work:  BEGIN is a block.
>
>    my $x = 1;
>    BEGIN { %MY::{'$y'} = \$x }
>    print $y;

Even worse, you should be able to modify lexicals even outside your scope.

sub violate_me {
    caller(1).MY{'$y'} := caller(1).MY{'$x'};    # hypothetical syntax
}

{
    my $x = 1;
    my $y;     # Might be able to BEGIN { violate_me() } instead
    violate_me();
    print $y;
}

Ashley Winters

--
When you do the community's rewrite, try to remember most of us are idiots.

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