%{$b} = ( d => 1, e => 1 );
You simply remove the reference to the anonymous hash-ref so that it looks like a hash for the assignment operator.
You can even do this:
%{$b} = ( %{$b}, d => 1, e => 1 );
In these cases, %{$b} is just a visual convenience (although in some cases it may be syntactic ambiguity) for %$b .
... or you could do ...
foreach ( qw/ de / ) { $b->{$_} = 1; }
Obviously, you probably do not intend to assign the value "1" to everyone. So what about the fragment:
@{$b}{ qw/ de / } = ( 1, 1 );
Slices are discussed in perldoc perldata , but a not-so-good description of perldoc for taking a fragment of an anonymous hash. To do this, you need to come to terms with all the Perl documentation on the links, and then extrapolate how to apply this to the slice syntax .... or check the anonymous hash fragments on PerlMonks.
source share