Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: chomp() is confusing

by TedPride (Priest)
on May 15, 2006 at 06:51 UTC ( #549386=note: print w/ replies, xml ) Need Help??


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

Chomp removes the current "input record separator", which can be changed by editing one of the built-in perl variables:

$/ = "\r\n";
Or you can just use regex to convert the line endings, which is probably safer if you don't know for sure what they're going to be:
for ("\r", "\n", "\r\n", "\n\r", "\r\r", "\n\n") { $line = 'text'.$_."text"; $line =~ s/$1/\n/g if m/(\r\n?|\n\r?)/; print "$line\n"; }
This basically detects what the line endings are from the first line ending, then converts everything to a standard \n.


Comment on Re: chomp() is confusing
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2014-12-22 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (130 votes), past polls