Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Why chomp() is not considering carriage-return

by dse (Novice)
on Apr 30, 2018 at 16:22 UTC ( #1213854=note: print w/replies, xml ) Need Help??

in reply to Why chomp() is not considering carriage-return

I do a lot of work in Windows (Cygwin), macOS, and Linux, and I have a Subversion repository containing a bunch of dotfiles I use on all three platforms. As a result I do, in fact, wind up getting a nice healthy mix of CRLF and LF line endings in all environments I work in. Because of that, $/ = "\r\n"; won't work.

Also, I can confirm that chomp in Cygwin perl will only remove \n from lines in text files with CRLF line endings ($/ is \n by default).

I just now learned about \R which *will* do the trick:


As an added bonus it will also work with old Macintosh line endings (\r)!

I honestly don't know why chomp doesn't do this in the year of our lord two thousand eighteen, other than backward combatibility.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2020-11-24 18:44 GMT
Find Nodes?
    Voting Booth?

    No recent polls found