in reply to Why doesn't exist work with hash slices?
It isn't obvious that exists @haystack{qw(aa bb cc dd)} should provide an "ANY" test. Some might think an "ALL" test would be correct. Thus, it definitely doesn't belong in core.
I'd suggest using any for clarity and to remove the need for !! (and the risk that one of your keys might be "0").
use List::Util qw(any first); my %haystack; @haystack{'aa'..'ff',"0"} = (); say any { exists $haystack{$_} } qw(aa bb cc dd); say any { exists $haystack{$_} } qw(zz 0); # OK say !! first { exists $haystack{$_} } qw(zz 0); # Oops!
Good Day,
Dean
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Why doesn't exist work with hash slices?
by LanX (Saint) on Sep 21, 2025 at 13:13 UTC | |
by Anonymous Monk on Sep 21, 2025 at 13:22 UTC | |
by ikegami (Patriarch) on Sep 21, 2025 at 16:16 UTC | |
by LanX (Saint) on Sep 21, 2025 at 14:02 UTC | |
by ysth (Canon) on Sep 21, 2025 at 20:15 UTC | |
by LanX (Saint) on Sep 22, 2025 at 09:17 UTC |