in reply to Re: Check last character of a string
in thread Check last character of a string
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Check last character of a string
by dHarry (Abbot) on Aug 07, 2008 at 09:09 UTC | |
by LesleyB (Friar) on Aug 07, 2008 at 11:48 UTC |