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

Re: local %SIG = (%SIG, $signame => ...) not working as expected?

Thread Previous | Thread Next
From:
Eric Wong
Date:
January 12, 2021 23:08
Subject:
Re: local %SIG = (%SIG, $signame => ...) not working as expected?
Message ID:
20210112230820.GA23604@dcvr
hv@crypt.org wrote:
> Eric Wong <p5p@yhbt.net> wrote:
> :I'm getting a hash(ref) of SIG overrides either as
> :a return value from another sub.  My workaround is something
> :like this:
> :
> :	my %sig = $self->some_callback;
> :	local $SIG{$_} = $sig->{$_} for keys %sig;
> :	...
> 
> I wouldn't expect that to work, but you can use a hash slice instead:

Right (not to mention the extra '->' :x)

>   local @SIG{keys %sig} = values %sig;
> 
> I do this sort of thing a lot when I want to localize a variable subset
> of elements, using a hash slice or array slice as relevant.

Cool, thanks, I will use that.  I did not realize keys and
values ordering would be consistent there.

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