perl5.10

Perl signal handlers are reset in END blocks

点点圈 提交于 2020-01-13 14:15:08
问题 This works as expected since Perl 5.10.1: SIGINTs are trapped. #!/usr/bin/perl use strict; use warnings; $SIG{INT} = sub { die "Caught a sigint $!" }; sleep(20); But here SIGINTs are not trapped. #!/usr/bin/perl use strict; use warnings; $SIG{INT} = sub { die "Caught a sigint $!" }; END { sleep(20); } This can be fixed by setting the handler again in the END block, like so: END { $SIG{INT} = sub { die "Caught a sigint $!" }; sleep(20); } But that won't work if you have more than one block:

Can I make sure Perl code written on 5.10+ will run on 5.8?

本小妞迷上赌 提交于 2020-01-01 09:30:14
问题 Some of the new features of Perl 5.10 and 5.12, such as "say", are defined as features, that you can enable or disallow explicitly using the "feature" pragma. But other additions, like the named capture groups of regexes, are implicit. When I write Perl using a 5.10+ interpreter, but want it to also run on 5.8, can I make Perl complain about using anything that's not in 5.8? Obviously, it is good practice to test your code on all major versions you intend it to run on, but it'd still be nice

Can't use string (“1”) as a subroutine ref while “strict refs” in use

巧了我就是萌 提交于 2019-12-22 09:12:11
问题 In a Perl daemon reacting to various events I'm trying to use a Null object pattern in 2 cases by creating anonymous subroutines, which should just return a value of 1 aka "true" (please scroll to the right to see the check subroutines for LOGIN and ALIVE events): package User; our %EVENTS = ( LOGIN => {handler => \&handleLogin, check => sub {1}, }, CHAT => {handler => \&handleChat, check => \&mayChat, }, JOIN => {handler => \&handleJoin, check => \&mayJoin, }, LEAVE => {handler => \

Why doesn't Perl file glob() work outside of a loop in scalar context?

。_饼干妹妹 提交于 2019-12-09 10:09:13
问题 According to the Perl documentation on file globbing, the <*> operator or glob() function, when used in a scalar context, should iterate through the list of files matching the specified pattern, returning the next file name each time it is called or undef when there are no more files. But, the iterating process only seems to work from within a loop. If it isn't in a loop, then it seems to start over immediately before all values have been read. From the Perl docs: In scalar context, glob

Perl signal handlers are reset in END blocks

◇◆丶佛笑我妖孽 提交于 2019-12-05 21:21:08
This works as expected since Perl 5.10.1: SIGINTs are trapped. #!/usr/bin/perl use strict; use warnings; $SIG{INT} = sub { die "Caught a sigint $!" }; sleep(20); But here SIGINTs are not trapped. #!/usr/bin/perl use strict; use warnings; $SIG{INT} = sub { die "Caught a sigint $!" }; END { sleep(20); } This can be fixed by setting the handler again in the END block, like so: END { $SIG{INT} = sub { die "Caught a sigint $!" }; sleep(20); } But that won't work if you have more than one block: handlers must be set again for every block. I've tried to figure this out and I can't find an explanation

Can't use string (“1”) as a subroutine ref while “strict refs” in use

孤街醉人 提交于 2019-12-05 13:27:24
In a Perl daemon reacting to various events I'm trying to use a Null object pattern in 2 cases by creating anonymous subroutines, which should just return a value of 1 aka "true" (please scroll to the right to see the check subroutines for LOGIN and ALIVE events): package User; our %EVENTS = ( LOGIN => {handler => \&handleLogin, check => sub {1}, }, CHAT => {handler => \&handleChat, check => \&mayChat, }, JOIN => {handler => \&handleJoin, check => \&mayJoin, }, LEAVE => {handler => \&handleLeave, check => \&mayLeave, }, ALIVE => {handler => sub {}, check => sub {1}, }, BID => {handler => \

Efficient pre-perl-5.10 equivalent of pack(“Q>”)

柔情痞子 提交于 2019-12-04 15:47:55
Update: Salva correctly points out that I was wrong about the introduction of the "Q" pack template. It's the ">" modifier that doesn't go back to 5.8. Perl 5.10 introduced the pack() modifier ">", which, for my use case with "Q" packs an unsigned quad (64bit) value in big endian . Now, I'm looking for an efficient equivalent for pack("Q>2", @ints) where @ints contains two 64bit unsigned ints. "Q>2" means "pack two unsigned quads in big-endian byte order". Obviously, I want this because I am (at least temporarily) tied to a pre-5.10 Perl. Update2: Actually, on further reflection, something as

Can I make sure Perl code written on 5.10+ will run on 5.8?

淺唱寂寞╮ 提交于 2019-12-04 04:26:05
Some of the new features of Perl 5.10 and 5.12, such as "say", are defined as features, that you can enable or disallow explicitly using the "feature" pragma. But other additions, like the named capture groups of regexes, are implicit. When I write Perl using a 5.10+ interpreter, but want it to also run on 5.8, can I make Perl complain about using anything that's not in 5.8? Obviously, it is good practice to test your code on all major versions you intend it to run on, but it'd still be nice to have Perl warn me automatically. When I want to ensure that a program will run under particular

The good, the bad, and the ugly of lexical $_ in Perl 5.10+

╄→гoц情女王★ 提交于 2019-11-29 23:35:25
Starting in Perl 5.10, it is now possible to lexically scope the context variable $_ , either explicitly as my $_; or in a given / when construct. Has anyone found good uses of the lexical $_ ? Does it make any constructs simpler / safer / faster? What about situations that it makes more complicated? Has the lexical $_ introduced any bugs into your code? (since control structures that write to $_ will use the lexical version if it is in scope, this can change the behavior of the code if it contains any subroutine calls (due to loss of dynamic scope)) In the end, I'd like to construct a list

The good, the bad, and the ugly of lexical $_ in Perl 5.10+

旧巷老猫 提交于 2019-11-28 20:22:44
问题 Starting in Perl 5.10, it is now possible to lexically scope the context variable $_ , either explicitly as my $_; or in a given / when construct. Has anyone found good uses of the lexical $_ ? Does it make any constructs simpler / safer / faster? What about situations that it makes more complicated? Has the lexical $_ introduced any bugs into your code? (since control structures that write to $_ will use the lexical version if it is in scope, this can change the behavior of the code if it