in reply to Re^2: Bloated code of loops and conditionals
in thread Bloated code of loops and conditionals
Regarding your first question, yes, that was a typo (now fixed).
A hash slice is a way to access several values of a hash using a list of keys. For regular hashes, for example,
has the same effect as@hash{ qw( foo bar baz ) } = ( 1, 2, 3 );
You can use slices to copy several values from one hash to another. E.g.$hash{ foo } = 1; $hash{ bar } = 2; $hash{ baz } = 3;
The last line copies three key-value pairs from %orig to %copy. In the code I posted earlier, the only difference is that the accessing of the RHS slice is done via a reference ($d) to a hash instead of a regular hash:@keys = qw( foo bar baz ); @copy{ @keys } = @orig{ @keys };
Once you dereference a hash ref you can use it like any other hash.@h{ @flds } = @{ $d }{ @flds }; # hash slice assignment
Slices are discussed in perldata, and using references in perlreftut and perlref.
the lowliest monk
|
|---|