Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

(Ovid) RE: Unix \n vs. DOS \n

by Ovid (Cardinal)
on Jul 15, 2000 at 21:00 UTC ( [id://22713]=note: print w/replies, xml ) Need Help??


in reply to Unix \n vs. DOS \n

As a side note, don't use chop to get rid of newlines. I see this all the time in programs and it makes me cringe. You want to use chomp.

chomp will only remove the last character if it's a newline. Consider the following "harmless" code:

#!/usr/bin/perl -w use strict; while (<DATA>) { chop; print "$_\n"; } __DATA__ this is a test this is another
You can't see it in the above code, but I deliberately did not hit "Enter" after the last line. I even hit backspace a few times to ensure that there was nothing after the word "another". The result?
this is a test this is anothe
chop happily removed the "r" in another. chomp was designed for situations like that and should be used where appropriate.

Cheers,
Ovid

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2024-04-24 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found