On Wed, Sep 29, 2004 at 04:43:50PM -0000, Chris Kelly wrote:
> Open should return false when using $1 as a file handle considering $1 is a
> read-only variable:
>
> $ perl -we'open $1, "/dev/null" or die "open: $!"'
Actually, it should die, in a similar fashion to the following:
$ perl585 -we '$1->{foo}=1'
Modification of a read-only value attempted at -e line 1.
since both involve autovivification of a readonly value.
The change below to the development version of Perl fixes this.
Dave.
--
The warp engines start playing up a bit, but seem to sort themselves out
after a while without any intervention from boy genius Wesley Crusher.
-- Things That Never Happen in "Star Trek" #17
Change 23342 by [EMAIL PROTECTED] on 2004/09/30 20:51:31
[perl #31767] open $1, "file" doesn't raise an exception
Affected files ...
... //depot/perl/pp.c#426 edit
... //depot/perl/t/io/open.t#41 edit
Differences ...
==== //depot/perl/pp.c#426 (text) ====
@@ -159,6 +159,8 @@
/* If this is a 'my' scalar and flag is set then vivify
* NI-S 1999/05/07
*/
+ if (SvREADONLY(sv))
+ Perl_croak(aTHX_ PL_no_modify);
if (PL_op->op_private & OPpDEREF) {
char *name;
GV *gv;
==== //depot/perl/t/io/open.t#41 (xtext) ====
@@ -12,7 +12,7 @@
$Is_VMS = $^O eq 'VMS';
$Is_MacOS = $^O eq 'MacOS';
-plan tests => 107;
+plan tests => 108;
my $Perl = which_perl();
@@ -315,3 +315,9 @@
'sub f { open(my $fh, "xxx"); $fh = "f"; } f; f;print "ok"',
'ok', { stderr => 1 },
'#29102: Crash on assignment to lexical filehandle');
+
+# [perl #31767] Using $1 as a filehandle via open $1, "file" doesn't raise
+# an exception
+
+eval { open $99, "foo" };
+like($@, qr/Modification of a read-only value attempted/, "readonly fh");