in reply to Consise way to filter out keys with undef values from a hash slice?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Consise way to filter out keys with undef values from a hash slice?
by choroba (Cardinal) on Jun 02, 2020 at 09:21 UTC | |
by kcott (Archbishop) on Jun 02, 2020 at 09:52 UTC | |
by choroba (Cardinal) on Jun 02, 2020 at 10:00 UTC | |
by kcott (Archbishop) on Jun 02, 2020 at 10:02 UTC |