Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by c (Hermit)
on Dec 29, 2001 at 05:14 UTC ( [id://135041]=note: print w/replies, xml ) Need Help??


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

chomp is only going to remove the trailing newline character of the entire line. my issue is that i may have multiple new lines within my hash value, so chomp won't do it for me.

-c

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

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

    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-)

      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://135041]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-24 08:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found