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

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

Thread Next
From:
Eric Wong
Date:
January 12, 2021 19:31
Subject:
local %SIG = (%SIG, $signame => ...) not working as expected?
Message ID:
X/35ISzCm0DZ7ICZ@dcvr
Hi all, I noticed "local %SIG = (%SIG, PIPE => sub { ... })"
wasn't restoring the old PIPE handler as I expected when I left
that scope, but "local $SIG{PIPE} = sub { ... }" restores the
old handler fine.

I've relied on a similar thing "local %ENV = (%ENV, k => $v)"
for ages, so is this anomaly for %SIG documented/expected?

Example here:
----------8<---------
use strict;
use warnings;
use Data::Dumper;
$Data::Dumper::Deparse = 1;

# this works as expected
print 'outside before ', Dumper($SIG{PIPE});
{
	local $SIG{PIPE} = sub { print "SIGPIPE\n" };
	print 'inside #1', Dumper($SIG{PIPE});
}
print 'outside middle expect and is undef', Dumper($SIG{PIPE});

# this does not work as expected
{
	local %SIG = (%SIG, PIPE => sub { print "SIGPIPE\n" });
	print 'inside #2 is sub', Dumper($SIG{PIPE});
}
print 'outside after expect undef, is sub?: ', Dumper($SIG{PIPE});
kill 'PIPE', $$;
select undef, undef, undef, 0.1; # wait for SIGPIPE to hit
# "SIGPIPE\n" printed, why?
----------8<---------
Thanks for any answer you can provide.

Perl 5.32.0 on FreeBSD 11.x, but happens on 5.28.1 on Debian 10, too

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