G'day nysus,
"Is there a good, more perlish way of pulling this off?"
In the absence of any information about wanting to capture the deleted keys, I'd probably just do this:
delete @ta{grep !defined $ta{$_}, keys %ta};
I'm not sure if the way you've constructed %ta is really what you intended; however, with Perl 5.30.0 I get no errors or warnings:
$ perl -Mstrict -Mwarnings -E ' my %args = (profile => "foo"); my %ta = %args{qw{profile user password}}; say "BEFORE:"; say for keys %ta; delete @ta{grep !defined $ta{$_}, keys %ta}; say "AFTER:"; say for keys %ta; ' BEFORE: profile password user AFTER: profile
— Ken
In reply to Re: Consise way to filter out keys with undef values from a hash slice?
by kcott
in thread Consise way to filter out keys with undef values from a hash slice?
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |