perl5
perl5 copied to clipboard
inconsistent behavior of dup open w/ barewords under `use strict`
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
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.