perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

inconsistent behavior of dup open w/ barewords under `use strict`

Open mauke opened this issue 1 year ago • 1 comments

Description If you use open to duplicate a bareword filehandle, it seems to be exempt from use strict (is this documented anywhere?), but only sometimes.

Steps to Reproduce

$ perl -e 'use strict; open my $fh, ">&", STDOUT or die $!'
$ perl -e 'use strict; open my $fh, ">>&", STDOUT or die $!'
Bareword "STDOUT" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.
$ perl -e 'use strict; open my $fh, "<&", STDIN or die $!'
Bareword "STDIN" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.
$ 

Expected behavior

$ perl -e 'use strict; open my $fh, ">&", STDOUT or die $!'
$ perl -e 'use strict; open my $fh, ">>&", STDOUT or die $!'
$ perl -e 'use strict; open my $fh, "<&", STDIN or die $!'
$ 

Perl configuration

This is perl 5, version 40, subversion 0 (v5.40.0) built for x86_64-linux-thread-multi-ld

mauke avatar Aug 04 '24 14:08 mauke

Similarly, using the -M switch on the command-line:

$ perl -Mstrict -e 'open my $fh, ">&", STDOUT or die $!'

$ perl -Mstrict -e 'open my $fh, ">>&", STDOUT or die $!'
Bareword "STDOUT" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.

$ perl -Mstrict -e 'open my $fh, "<&", STDOUT or die $!'
Bareword "STDOUT" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.

jkeenan avatar Aug 04 '24 14:08 jkeenan