in reply to add a character at the end of a string

I guess there are alternatives, but it works:

# can't be called with a literal string as arg # but that wasn't asked for :) sub appendMissingSlash { return $_[0] .= substr($_[0], -1) eq "/" ? "" : "/"; } my $string = "/tmp/check"; appendMissingSlash($string); print $string,"\n"; __END__ /tmp/check/

Update: I didn't use a regex, as other examples given suggest, because we know the position and the character to check for, using the regex engine seemed overkill to me


An intellectual is someone whose mind watches itself.
-- Albert Camus