Gossamer Forum
Home : General : Perl Programming :

Removing an & from the end of a string.

Quote Reply
Removing an & from the end of a string.
I have a problem. I am trying to figure out a way to remove the last & character from a string. There are other & characters in the string that I don't want to be removed, but the last one at the very end of the string I do. What is the perl code to do this?

I was thinking that $str =~ s//&$//; would work. Any help?
Quote Reply
Re: Removing an & from the end of a string. In reply to
The last character of any string can be removed with "chop"

To specifically remove the last character, *IF* it is an '&' try....

$str =~ s/&$//;

substitute '&' with nothing if it's the last character.
Quote Reply
Re: Removing an & from the end of a string. In reply to
It works. Thanks