Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: Re: Removing the ^M character, but also removing the newline

by steves (Curate)
on Dec 30, 2001 at 03:01 UTC ( [id://135166]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Removing the ^M character, but also removing the newline
in thread Removing the ^M character, but also removing the newline

Tell chomp what your newline is like this:

local $/ = "\r\n"; chomp;

Chomp chomps whatever you tell it a newline is. local localizes that setting so it's automagically replaced with the standard newline for your system when the block the local setting is within is done.

Name another language that makes stripping newlines this easy. 8-)

Replies are listed 'Best First'.
Re: Re: Re: Re: Removing the ^M character, but also removing the newline
by steves (Curate) on Dec 30, 2001 at 03:05 UTC

    Almost forgot. I wrote this simple dos_chomp function for cases where there may or may not be a CR (^M) before the LF. Enjoy!

    sub dos_chomp { if (!defined(@_[0])) { chomp; s/\r$//; } else { for (@_) { chomp; s/\r$//; } } return wantarray ? @_ : @_[0]; }

Log In?
Username:
Password:

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

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

    No recent polls found