in reply to matching elements in a list in a logical OR fashion
This is one of my favorite tricks,
The customary way is to join '|', @array in constructing the regex.my $re = do { local $" = '|'; qr/@array/; }; if ($bigstring =~ /$re/ ) { #... }
If @array has regex metacharacters, it may be needful to escape them:
my $re = do { local $" = '|'; qr/@{[map { quotemeta } @array]}/; };
After Compline,
Zaxo
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: matching elements in a list in a logical OR fashion
by meetraz (Hermit) on Jun 15, 2004 at 04:03 UTC | |
Re^2: matching elements in a list in a logical OR fashion
by hardburn (Abbot) on Jun 15, 2004 at 13:57 UTC | |
Re^2: matching elements in a list in a logical OR fashion
by didier (Vicar) on Jun 15, 2004 at 06:25 UTC |