in reply to Re: Parsing an Array of Hashes, Modifying Key/Value Pairs
in thread Parsing an Array of Hashes, Modifying Key/Value Pairs

G'day kcott,

just wondering:

my @keeps = qw{a b}; my %to_keep = map { $_ => 1 } @keeps; ... delete @$sms_ref{ grep { ! exists $to_keep{$_} } keys %$sms_re +f };
using exists is a bit redundant if you already intialize the hash with true values...

so either dropping the exists

... delete @$sms_ref{ grep { ! $to_keep{$_} } keys %$sms_ref };
or initializing with undef
my %to_keep; @to_keep{ qw{a b} } = (); ...

should have the same effect.

Or am I missing something?

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^3: Parsing an Array of Hashes, Modifying Key/Value Pairs
by kcott (Archbishop) on May 14, 2013 at 04:11 UTC

    Thanks for picking that up - I've updated my node. I suspect my intent, with including the exists, was to avoid autovivification; however, no autovivification occurs there anyway — I think it might have done long ago (Perl3/4?).

    -- Ken