See delete:
perl -MData::Dumper=Dumper -le '%hash = ( a=>3, b=>4, c=>1, d => 7 ); +@ary = qw(b c); @nhash{@ary} = delete @hash{@ary}; print Dumper \%has +h; print Dumper \%nhash;' $VAR1 = { 'a' => 3, 'd' => 7 }; $VAR1 = { 'c' => 1, 'b' => 4 };
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
In reply to Re: Slicing and Destructing a Hash
by xdg
in thread Slicing and Destructing a Hash
by neversaint
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |