in reply to When do you use chop instead of chomp?

Chop removes the last character, no matter what it is, EOL, or what ever. Chomp only removes EOL marks if there is one. If not, it does nothing.

The EOL mark Chomp removes corresponds to the current value of $/, so you may want to check that as well on your system.

Chomp also returns the total number of characters removed so you get a 1 or a 0 responce. Chop returns nothing.

webadetp.net
  • Comment on Re: When do you use chop insetad of comp?

Replies are listed 'Best First'.
Re: Re: When do you use chop insetad of comp?
by maverick (Curate) on Mar 02, 2002 at 20:23 UTC
    minor correction. chop returns the character removed.
    $string = "abc"; print chop $string; # prints 'c' print $string; # prints 'ab'

    /\/\averick
    perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

      Ah.. and so it does.. Most usful that. Thanks