Danny has asked for the wisdom of the Perl Monks concerning the following question:
gives 'Use of uninitialized value $h{"a"} in array dereference at -e line 1.'perl -we 'my %h; my @x = ( @{$h{a}} )'
which seems desirable, but
creates the $h{a} key which seems kinda bad. Why is the foreach context treating ( @{$h{a}} ) differently?perl -wE 'my %h; foreach $x ( @{$h{a}} ) { say $x }; exists $h{a} and +print "true\n"'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: autovivified hash key with foreach $x ( @{$h{a}} ) {}
by Anonymous Monk on May 17, 2024 at 17:34 UTC | |
by Danny (Chaplain) on May 17, 2024 at 17:46 UTC | |
|
Re: autovivified hash key with foreach $x ( @{$h{a}} ) {}. (Update x2)
by LanX (Saint) on May 17, 2024 at 17:45 UTC | |
by ikegami (Patriarch) on May 18, 2024 at 12:51 UTC | |
by LanX (Saint) on May 18, 2024 at 13:23 UTC | |
by ikegami (Patriarch) on May 18, 2024 at 13:35 UTC |