The fact is that your x= tricks works as just as much as the undef() because of undocumented behaviour. This is shown by
my $foo;
sub context :lvalue { $foo = wantarray ? 'list' : 'scalar' }
context() x= 1;
print $foo;
__END__
scalar
or using simpler means:
use Data::Dumper;
my %foo = qw/ a 1 b 2 /;
@foo{qw/ a b /} x= 0;
print Dumper \%foo;
__END__
$VAR1 = {
'a' => '1',
'b' => ''
};
A trick that
does work though is the reference trick. All these other solutions work because of autovivification. So let's use
\ whose behaviour explicitly is documented.
\@foo{@list};
ihb
See perltoc if you don't know which perldoc to read!