in reply to Re^3: Hash/Array slice : how to exclude items?
in thread Hash/Array slice : how to exclude items?
delete returns the thing(s) deleted, not the things remaining after deletion, so that idea won't fly.
The effect of local is undone at the end of the block (scope) in which it was done, so your proposed examples cannot work - the elements have already been restored by the time Dumper() gets a look at the hash.
If you can put the Dumper() call inside the block, then it will work:
print do { delete local @$hashref{ @$bad_keys }; Dumper($hashref) };For a complete example:
% perl -we '%a=(schema=>1,log=>2,aa=>3); use Data::Dumper; print do { delete local @a{qw{ schema log }}; Dumper(\%a) }' $VAR1 = { 'aa' => 3 }; %
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Hash/Array slice : how to exclude items?
by bliako (Abbot) on Jan 24, 2023 at 23:27 UTC |