in reply to looking for simple way to check scalar against array
my %in; undef @in{1, 2, 3..9, -12}; print "$i is a 1, 2, 3, 4, 5, 6, 7, 8, 9, or -12\n" if exists $in{$i};
This method's advantage is that you can reuse the hash if you need to check if multiple variables are in the set, while still being extremely efficient.
|
|---|