in reply to A 'strange' character("^M") of contrasting color appearing unexpededly at the end of lines of a unix file. How can it be removed?

Using the chop function

When reading files from Windows on UNIX it is often useful to:
local $/ = "\r\n"; chomp $string;
(rather than chop)
  • Comment on Re: A 'strange' character("^M") of contrasting color appearing unexpededly at the end of lines of a unix file. How can it be removed?
  • Download Code

Replies are listed 'Best First'.
Re^2: A 'strange' character("^M") of contrasting color appearing unexpededly at the end of lines of a unix file. How can it be removed?
by Anonyrnous Monk (Hermit) on Dec 14, 2010 at 18:20 UTC

    or even use the ":crlf" PerlIO layer to automatically translate \r\n <—> \n.

    On Windows, the layer is active by default, which is why the "^M problem" does not occur. But there's nothing that would keep you from using it on Unix, too, in case you need to handle Windows-style files.