Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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 (Chancellor)
on Apr 03, 2022 at 18:33 UTC ( [id://11142653]=note: print w/replies, xml ) Need Help??


in reply to 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?

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11142653]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-28 14:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found