good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Consise way to filter out keys with undef values from a hash slice?by LanX (Saint) |
on Jun 01, 2020 at 21:16 UTC ( [id://11117572]=note: print w/replies, xml ) | Need Help?? |
This > 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.
editThere is - unfortunately - no "slice when exists" operator in Perl. Otherwise (ab)using hashes for set operations like intersections would be trivial.
Cheers Rolf
In Section
Seekers of Perl Wisdom
|
|