in reply to Re: Display $var content
in thread Display $var content

Chomp doesn't remove the trailing newline, It removes any line ending that corresponds to the current value of $/ which isn't always "\n". On DOS/WinXx machines it winds up being "\r\n" and under Mac winds up being "\r" if I remember them right. It can't hurt to let it alone as it might drop a few chars from the overall transmission and may make some wonky web clients a bit happier...

--
$you = new YOU;
honk() if $you->love(perl)

Replies are listed 'Best First'.
Re: Re: Re: Display $var content
by chipmunk (Parson) on Feb 27, 2001 at 04:13 UTC
    On Windows, $/ is still "\n". The "\r\n" line-endings are converted to "\n" automatically when a file is read, and "\n" is converted to "\r\n" when a file is written. (Unless binmode has been called on the filehandle.)

    On a Mac, $/ is still "\n", but "\n" means "\015" and "\r" means "\012".

    So, if $/ has not been set explicitly,

    $orig = <>; chomp($new = $orig); $new = "$new\n"; print $orig eq $new ? "yes" : "no";
    will print yes on Unix, Windows, and Mac.

    Of course, if $/ has been changed, then all bets are off. :)