I am working with the following code. (The character after the + signs is a lower case L. The character after that is the key above the TAB key.)
@nestedListPrefixes = ("++++l`","+++l`","++l`","+l`","l`");
$nestedListPrefixCount = $#nestedListPrefixes;
for ($i=0; $i<=$nestedListPrefixCount; $i++){
$listBegin = $nestedListPrefixes[$i];
.
.
.
}
The variable $theContent is from a form field, into which I've typed some text that includes the string "++++l`". Here's what I can't figure out. The first time through the loop, I test for the value of $listBegin with a debug line:
print ($listBegin eq "++++l`");
It returns "1".
I test the contents of $theContent:
print($theContent =~ /\+\+\+\+l`/);
It returns "1".
Yet, when I test this:
print($theContent =~ /$listBegin/);
It returns null.
If I change the test string to something without the + char, it works. So, Perl must be interpreting that + in some funky way. How do you make Perl match characters like that?
Thanks much!
Perry
for ($i=0; $i<=$nestedListPrefixCount; $i++){
$listBegin = $nestedListPrefixes[$i];
$listBegin=~s/(\W)/\\$1/g; # Escape non-word characters
print($theContent =~ /$listBegin/);
}