in reply to Checking for occurrence in comma separated string
You are doing:if($thestring =~/13/) { print "13 is in the string"; }
So in fact you are searching for the 10char string inside a 2 char string, the thing on the left of =~ is the variable/string in which you want to search, and the thing on the right is the regular expression you want to search for, so to make your code snippet work the way you want it do it like this:if("13" =~ /13,130,213/) { print "13 is in the string"; }
my $thestring = "13,130,213"; my $thecheck = "13"; if($thestring =~ /$thecheck/){ print "$thecheck is in $thestring\n"; }
|
|---|