in reply to How do I capture the last character in a string?

Thanks guys

I always forget about 'chop'

Thanks again!

  • Comment on Re: How do I capture the last character in a string?

Replies are listed 'Best First'.
Re: Re: How do I capture the last character in a string?
by perlplexer (Hermit) on Apr 30, 2003 at 13:59 UTC
    Note that chop() alters the string it's operating on.

    --perlplexer
Re: Re: How do I capture the last character in a string?
by hmerrill (Friar) on Apr 30, 2003 at 14:11 UTC
    Just for the sake of completeness, I wanted to make sure you didn't also forget about 'chomp' - here's the 1st few lines of 'perldoc -f chomp':
    chomp VARIABLE chomp( LIST ) chomp This safer version of "chop" removes any trailing strin +g that corresponds to the current value of $/ (also known as $INPUT_RECORD_SEPARATOR in the "English" module). It r +eturns the total number of characters removed from all its arg +uments. It’s often used to remove the newline from the end of a +n input record when you’re worried that the final record may be + missing its newline. When in paragraph mode ("$/ = """), it re +moves all trailing newlines from the string. When in slurp m +ode ("$/ = undef") or fixed-length record mode ($/ is a referenc +e to an integer or the like, see perlvar) chomp() won’t remove +any- thing. If VARIABLE is omitted, it chomps $_. Example: while (<>) { chomp; # avoid \n on last field @array = split(/:/); # ... }
    HTH.