On Tue, Jan 12, 2021, at 4:11 PM, Eric Wong wrote: > Uri Guttman <uri@stemsystems.com> wrote: > > i wonder why he copies %ENV. he should be able to just do: > > > > local( $SIG{$signame} ) = blah ; > > > > the is faster and doesn't have the odd number thing you mention > > Laziness :) 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; "something like" can cover a lot of ground here, but are you sure that your workaround isn't so close to this that, like this, it just doesn't work? X for Y is equivalent to "for (Y) { X }" including the enclosing scope, which delimits the effect of local. use v5.30.0; use Data::Dumper; our %hash = (a => 1, b => 1); { local $hash{$_} = 2 for keys %hash; print Dumper(\%hash); } { local %hash = %hash; $hash{$_} = 2 for keys %hash; print Dumper(\%hash); } print Dumper(\%hash); …which outputs… $VAR1 = { 'a' => 1, 'b' => 1 }; $VAR1 = { 'a' => 2, 'b' => 2 }; $VAR1 = { 'a' => 1, 'b' => 1 }; -- rjbsThread Previous | Thread Next