in reply to Why is "undef" after passing not readonly anymore?

It's to permit autovivification:

use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); sub aaa($) {my ($a) = @_; $a->{a} = 1; say STDERR dump($a); } aaa({}); aaa(undef); aaa(0);

Produces:

{ a => 1 } { a => 1 } Can't use string ("0") as a HASH ref while "strict refs" in use at C:\ +Phil\Perl\PerlMonks\undef2.pm line 8.

Replies are listed 'Best First'.
Re^2: Why is "undef" after passing not readonly anymore?
by LanX (Saint) on Sep 07, 2012 at 08:37 UTC
    Hi

    Good point, but I think it's even simpler!

    There are so many cases where undef is occasionally passed as argument, that inner variables of a sub like $_[0] must be writable.

    Cheers Rolf