in reply to Comparing multiple strings
Here's a few ways...
If you're using a version of Perl that has smart match:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing multiple strings
by bigup401 (Pilgrim) on Jan 15, 2019 at 22:17 UTC | |
by pryrt (Abbot) on Jan 15, 2019 at 22:35 UTC | |
by pryrt (Abbot) on Jan 15, 2019 at 22:42 UTC | |
by hippo (Archbishop) on Jan 15, 2019 at 22:36 UTC | |
|
Re^2: Comparing multiple strings
by bigup401 (Pilgrim) on Jan 15, 2019 at 19:09 UTC |