in reply to Why chomp doesn't work?

No, chomp works fine. On Unix the end of line \n is a single \cJ character, which is what it's removing. On CP/M derivatives it's \cM\cJ, so on wintendo it's removed correctly. Your problem is that you're transferring your file in such a way that it's preserving the other platform's end of line marker. Either transfer the file in such a way that line endings are translated, or use something like dos2unix to correct the line endings beforehand (or just use the same s/\cM+$// after the chomp to be sure).

Replies are listed 'Best First'.
Re^2: Why chomp doesn't work?
by bart (Canon) on Jun 14, 2004 at 13:35 UTC
    You're wrong, on Windows/DOS, Perl thinks of "\n" as chr(10), too. It's only that when reading from a text file, thus with binmode disgarded, the contents read from the file is modified so a chr(10) (="\n") is substituted for every chr(13).chr(10) pair in the file.

    On printout to a text file handle, the reverse happens: Every chr(10) is replaced by chr(13).chr(10).

    The net effect, and the whole point of this elaborate exercise, is that on these platforms, "\n" is a single character too.

      You forgot your </pedant> tag there. :)

      This is correct, in memory it is represented as a single \cJ and the translation (on a filehandle that binmode hasn't been enabled on) to/from \cM\cJ happens when passing through STDIO's claws. See ISSUES / Newlines in perldoc perlport for the gory details.