if ($item =~ /$exp/) {
print 'yes';
}
My problem is that $item has a '*' in it at times.
I'm getting weird behavior so i'm asking.
Is this correct?
$exp =~ s/\*/\\\*/g;
if ($item =~ /$exp/) {
print 'yes';
}
Maybe. Depends on what that code snippet of yours is supposed to do. And
you forgot to tell us what it is supposed to do.
>$exp =~ s/\*/\\\*/g;
>if ($item =~ /$exp/) {
> print 'yes';
>}
jue
You are probably looking for \Q...\E, see perldoc perlre.
HTH,
M4
Could you be clearer about your question by posting a runnable example
that illustrates your problem?
------------------------8<----------------------
#!perl
use strict;
use warnings;
my $re = ' \* ';
while (<DATA>) {
chomp;
print;
print /$re/ ? " Matches\n" : " Doesn't\n";
}
__DATA__
lorem * ipsum
dolor sit amet
adispic*ing
------------------------8<----------------------
lorem * ipsum Matches
dolor sit amet Doesn't
adispic*ing Doesn't