develooper Front page | perl.perl5.porters | Postings from January 2022

Re: Can't localize lexical variable $x at ...

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
January 31, 2022 21:18
Subject:
Re: Can't localize lexical variable $x at ...
Message ID:
YfhSCsPruvFdOKr5@iabyn.com
On Tue, Jan 25, 2022 at 03:59:58PM +0000, hv@crypt.org wrote:
> It would probably be useful to have examples where that distinction
> makes a difference

Aren't we talking about the different between

1) container localisation:

    my $x = 1;
    my $rx = $x;
    local $x = 2;
    print $$rx, $x; # prints 2,2

2) value localisation:

    my $x = 1;
    my $rx = $x;
    local $x = 2;
    print $$rx, $x; # prints 1,2

local() normally does container localisation. I think for consistency it
should do that with lexical vars too.

i.e.

    {
        local $lex = $foo;
        ...
    }

should be equivalent to


    for $lex ($foo) {
        ...
    }

-- 
Modern art:
    "That's easy, I could have done that!"
    "Ah, but you didn't!"

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