in reply to Consise way to filter out keys with undef values from a hash slice?
> grep { $args{$_ } } keys %ta;
Will also delete all false values like 0 or "" . You rather want to test on definedness and not truth
This keys on a slice
> keys %args{'profile', 'user', 'password'};
Is over complicated and doesn't make sense.
You obviously just want the list of keys directly
'profile', 'user', 'password'
But I concur with choroba that using exists right from the beginning is the cleanest way, since undef could be a legal value.
There is - unfortunately - no "slice when exists" operator in Perl.
Otherwise (ab)using hashes for set operations like intersections would be trivial.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Consise way to filter out keys with undef values from a hash slice?
by LanX (Saint) on Jun 01, 2020 at 22:00 UTC | |
|
Re^2: Consise way to filter out keys with undef values from a hash slice?
by jo37 (Curate) on Jun 02, 2020 at 19:05 UTC | |
by LanX (Saint) on Jun 02, 2020 at 22:54 UTC |