Do you know where your variables are? | |
PerlMonks |
Re^2: Check last character of a stringby LesleyB (Friar) |
on Aug 06, 2008 at 09:46 UTC ( [id://702584]=note: print w/replies, xml ) | Need Help?? |
Mmmm I'm still plodding along in 5.8 not even tried 5.10 yet so if ($var == "\\") doesn't even look like a regular expression to me and I know that I use strncmp in C. And the logic is wrong; even using eq you'll find that logic will test if your string is equal to "\" and you originally said you wanted to test whether the end of the string contained '\'.
Try using if ($var =~ /\\$/){ instead.
See perlrequick for an explanation of the $. Update: Sorry didn't read the code properly to realise you were grabbing the last character of the string before checking it. The '==' threw me, Your Honour! I don't think it is necessary to do that. The above regexp should work for any string and should detect a '\' at the end of the whole string. It should work anyway but you don't need to strip that char out to examine it.
In Section
Seekers of Perl Wisdom
|
|