I have to match a string in format Krait400.1C.28, when I store it in a variable:
$string_to_match = "Krait400.1C.28" foreach (@line) { if($_ =~ /$string_to_match/i) { print "found"; } else { print "notfound"; } } it doesn't match. But if I replace $string_to_match with "Krait400.28.1C" it matches. Also, there are other strings which do match and in the same format like xxxx.yy.1C, but I have problems with some of them like "Krait400.28.1C", it is acting really weird
I have counted characters, everything is same, but I don't know why it is not matching!
Please help me out!
/\Q$string_to_match/ito escape any metacharacters. In this case the dots in the pattern will match any single character in the object text, instead of matching dots. But this isn't the source of your problem, as it would make it match lines when it shouldn't and your problem is the reverse of that;after the assignment. After adding the string to the@linearray, I got "found" back.=~ /foo$string_to_match/. We can speculate all day about what the OP's code really is and why they (apparently) mis-copied it when composing this question, but that seems rather pointless.