Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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
Domain Nodelet?
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 wandering the Monastery: (2)
As of 2022-05-28 10:38 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (99 votes). Check out past polls.