My runtime environment is always *nix, so for me, perl's default "chomp" behavior is to remove just a final "\n". When I'm writing a script that might need to handle text files from both *nix (LF) and ms-windows (CRLF), I use the following instead of chomp:
s/[\r\n]+$//
Because I use macosx a lot, I also sometimes see text files that use just CR instead of LF. Then there are cases where a file isn't consistent in terms of its CR vs. LF vs. CRLF behavior, or where a file wasn't originally text data, but has been mishandled (corrupted by a "unix-to-dos" text-mode conversion as if it were text). It can get pretty maddening, so I wrote a script just to report diagnostics, and posted it here in a SoPW thread several years ago: Re: How to determine type of line endings in a text file from within a script

It boils down to the problem of getting to know the data you're dealing with, and taking appropriate steps to give it the treatment it needs.


In reply to Re: While i am executing a perl script in that one file will get as ouput in that ^M is priting and the actual output is getting disabled? by graff
in thread While i am executing a perl script in that one file will get as ouput in that ^M is priting and the actual output is getting disabled? by himanshu.chauhan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.