in reply to Chomp doesn't seem to work

if you have a file with indeterminate line-ending chars, I'd recommend
$line =~ s/[\r\n]+$//;

Dave.

Replies are listed 'Best First'.
Re^2: Chomp doesn't seem to work
by halley (Prior) on Feb 03, 2005 at 15:45 UTC
    Is there any reason you happened to anchor your regex with an "end-of-line" $ code? Because that will depend on the definition of a "line" too.

    If I'm stripping a single line thing, I'd use \z to anchor to the end of the string.

    Similarly, the \n and \r are semantic, referring to this platform's idea of newlines and returns. Specify exact encodings that you're encountering. For sources using ASCII or UTF-8, that's probably \x0A and \x0D.

    $text =~ s/[\x0D\x0A]+\z//;

    --
    [ e d @ h a l l e y . c c ]