regular expression matching
Tkil
tkil at scrye.com
Wed Jun 5 22:50:46 CDT 2002
>>>>> "Jason" == Jason White <jasona at inetarena.com> writes:
Jason> How exactly do I use a regular expression as a boolean value?
You just evaluate it in a boolean context. But that's probably not
what you meant.
Jason> $service="cns-noc_server1";
Jason> $rule="cns-noc";
Jason> if( WHAT DO I PUT HERE ) {
Jason> print "$rule is in $service \n";
Jason> } else {
Jason> print "$rule isn't in $service \n";
Jason> }
The answer depends on what you man by "in", when you say that "$rule
is in $service".
If you mean substring inclusion ("is $rule a substring of $service?"),
then you want "index". man perlfunc.
If you mean to interpret the contents of $rule as a regular
expression, and see if that regular expression matches something in
$service, then you want the bind operator "=~" and m// (or just //),
possibly also involving \Q (as Tom P. points out in a later post) or
qr//. All of this is covered in perlop and perlre.
The best way to do either of these depends a fair bit on how many
rules you plan on matching against how many services.
t.
TIMTOWTDI
More information about the Pdx-pm-list
mailing list