http://qs1969.pair.com?node_id=11110437

leszekdubiel has asked for the wisdom of the Perl Monks concerning the following question:

Hello Great Monks! Could anyone explain why this program dies? "x" valu in hashref $h shouldn't be modified... in the same manner as "y" was not modified...
#!/usr/bin/perl -CSDA use utf8; use Modern::Perl qw{2017}; use Data::Dumper; $Data::Dumper::Sortkeys = 1; my $h = {a => 1, b => "", c => 2}; my $d1 = Dumper($h); printf "grep: %s\n", (join " ... ", grep { $_ } $$h{a}, $$h{x}, $$h{b +}, $$h{c}); printf "test: %s\n", $$h{y} ? "yes" : "no"; my $d2 = Dumper($h); $d1 eq $d2 or die "\nFAIL! h{x} modified, h{y} not modified... why?\n +\n$d1\n$d2";
result:
grep: 1 ... 2 test: no FAIL! h{x} modified, h{y} not modified... why? $VAR1 = { 'a' => 1, 'b' => '', 'c' => 2 }; $VAR1 = { 'a' => 1, 'b' => '', 'c' => 2, 'x' => undef };