I usually solve this with a subroutine. I'll provide a few - one for regex matching and two for plain 'contains' or 'equals' matching.
The whole idea here is I'm just sticking the operator into a subroutine and calling each value in turn until either the list is exhausted or something matched successfully. I understand this somewhat of the idea behind the junction operators in perl6. Anyhow, check out List::Util for more thoughts along these lines.
sub qrany { $_ =~ $_[0] && return 1 for @_[1 .. $#_]; return } sub cany { index($_[0],$_) != -1 && return 1 for @_[1 .. $#_]; return + } sub eqany { $_ eq $_[0] && return 1 for @_[1 .. $#_]; return } # Contains tests if (cany( $string, qw[this or_this or_that]) {.... or # Equality tests if (eqany( $string, qw[this or_this or_that]) {.... or # Regex tests if (qrany( $string, qr/one regex/, qr/another regex/, qr/yet another regex/ )) { ....
Updated Added eqany and some comments on the usage of each
UpdatedFixed the words "three and two". Also added the second paragraph
Seeking Green geeks in Minnesota
In reply to Re: matching strings...
by diotalevi
in thread matching strings...
by powerhouse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |