Branch: refs/heads/yves/fix_19472_warns_on_undef_scalar_ref_open
  Home:   https://github.com/Perl/perl5
  Commit: 8f32f96f6821e68b506c23810e2fbd0eee36d5ba
      
https://github.com/Perl/perl5/commit/8f32f96f6821e68b506c23810e2fbd0eee36d5ba
  Author: Yves Orton <demer...@gmail.com>
  Date:   2022-03-04 (Fri, 04 Mar 2022)

  Changed paths:
    M doio.c
    M pod/perlfunc.pod
    M t/io/open.t

  Log Message:
  -----------
  Fix GH Issue #19472: read warnings from open($fh,">",\(my $x))

We produce all kinds of warnings if someone opens a scalar reference
that is undef. Prior to this we handled write operations ok, at
least in blead, but read operations would produce a plethora of
warnings. To me this analogous to treating an undef var as hash
and trying to read from it, we autovivify the undef var to be
a hash. So in this case we should just "autovivify" the referenced
scalar to be an empty string.

Eg. before this patch:

./perl -Ilib -wle'open my $fh,"+>", \(my $v); my @x=<$fh>; print 0+@x'
Use of uninitialized value $fh in <HANDLE> at -e line 1.
Use of uninitialized value $fh in <HANDLE> at -e line 1.
Use of uninitialized value $fh in <HANDLE> at -e line 1.
Use of uninitialized value $fh in <HANDLE> at -e line 1.
Use of uninitialized value $fh in <HANDLE> at -e line 1.
Use of uninitialized value $fh in <HANDLE> at -e line 1.
Use of uninitialized value $fh in <HANDLE> at -e line 1.
0

After it:
./perl -Ilib -wle'open my $fh,"+>", \(my $v); my @x=<$fh>; print 0+@x'
0


Reply via email to