in reply to Accidentally creating hash elements with grep { defined } on a hash slice
You can use a list slice to get around the key creation, too. An ugly hack it is, though.
my @keys = qw( a b c d ); my %h = ( b => 'b' ); my @found = grep {defined} (@h{@keys})[0..@keys]; print Dumper \%h; print Dumper \@found
Output:
$VAR1 = { 'b' => 'b' }; $VAR1 = [ 'b' ];
TGI says moo
|
|---|