develooper Front page | perl.perl5.porters | Postings from July 2009

Re: delete local $a[$idx] - delete local $h{$key}

Thread Previous | Thread Next
From:
Vincent Pit
Date:
July 27, 2009 06:14
Subject:
Re: delete local $a[$idx] - delete local $h{$key}
Message ID:
4A6DA830.7070000@profvince.com

> 2009/7/25 Vincent Pit <perl@profvince.com>:
>   
>> I've just pushed a "deletelocal" branch to the repository that contains
>> the implementation of "delete local $a[$idx] - delete local $h{$key}".
>> This syntax was actually valid for a long time (at least since 5.6) but
>> didn't do anything. Following a suggestion from Ricardo, I've made it
>> equivalent "delete $a[$idx]; local $a[$idx]", except that it returns the
>> value before the localization.
>>     
>
> That's not really the equivalent, since $a[$idx] is restored afterwards, right?
>   
Yes. I've sent an amended message just after this one, but the list has
a lot of traffic those days so it was easily missed. Just to restate it,

    delete local $a[$idx]

is equivalent to

    do { my $val = $a[$idx]; local $a[$idx]; delete $a[$idx]; $val }

> This is a nice new feature and the implementation looks neat.
>
> Not sure where to document this -- probably with the local() main docs.
>   

I'm gonna add some doc for it to the branch then.

Thanks for unwarnocking it.

Vincent.


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