Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by ton (Friar)
on Dec 29, 2001 at 04:56 UTC ( [id://135031]=note: print w/replies, xml ) Need Help??


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

try chomp
-ton
-----
Be bloody, bold, and resolute; laugh to scorn
The power of man...
  • Comment on Re: Removing the ^M character, but also removing the newline

Replies are listed 'Best First'.
Re: Re: Removing the ^M character, but also removing the newline
by c (Hermit) on Dec 29, 2001 at 05:14 UTC
    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

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-26 05:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found