kkavitha has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Unable to remove the ^M character
by planetscape (Chancellor) on Jul 24, 2009 at 05:35 UTC
Re: Unable to remove the ^M character
by ikegami (Patriarch) on Jul 24, 2009 at 06:05 UTC

    Why do you think it's a problem to get CRLF for line endings in Windows?

    You're having problems removing the CR chars because they are automatically removed when the file is read and automatically re-added when the file is written. That's what DOS and Windows applications do.

    I don't know if Tie::File has an option to treat the file as binary — it's kind of silly for a module that deals with lines — but you'd normally use binmode to disable this behaviour.

Re: Unable to remove the ^M character
by cdarke (Prior) on Jul 24, 2009 at 07:55 UTC
    You do not say which operating system you are running the Perl on. This is important because Windows has the notion of text files, whereas UNIX does not.

    When Perl on Windows reads a text file it removes the "\r" for you, so if you are running the code on Windows, it probably doesn't have a "\r" in the record to remove! Perl then adds the "\r" (^M) on Windows when you write the file as text with a "\n" line ending.

    If you wish to write a UNIX style file on Windows then set binmode on the file handle before writing the file.

      Thanks for your information. It is working fine.

      Tried with binmode. However it is working fine for the file which not resides with ^M. but ^M is lost for the file which resides with ^M

        <hi>,
        you can use this UNIX command dos2unix
        , -Raja
Re: Unable to remove the ^M character
by Your Mother (Archbishop) on Jul 24, 2009 at 05:50 UTC