if ($name ~~ [$t1, $t2]) {
...;
}
I've written match::smart which has a pure Perl implementation of smart match, which will allow you to do smart matching on older Perls:
use match::smart "match";
if (match $name, [$t1, $t2]) {
...;
}
A lot of people don't like smart match though because the rules for exactly how it behaves are kind of confusing. match::smart comes bundled with match::simple which has saner rules and will also do what you're looking for:
use match::simple "match";
if (match $name, [$t1, $t2]) {
...;
}
You can use List::Util's any function:
use List::Util "any";
if (any { $name eq $_ } $t1, $t2) {
...;
}
match::simple has an optional XS implementation, match::simple::XS, and if you can install it, that will probably be faster than List::Util or match::smart.
|