Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Unix \n vs. DOS \n

by greenhorn (Sexton)
on Jul 16, 2000 at 15:20 UTC ( #22766=note: print w/replies, xml ) Need Help??

in reply to Unix \n vs. DOS \n

I believe the fellow at work used chop because he wanted to have Perl return the line-ending character; chomp seems to return only a result code and not the "chomped" character.

I created a four-line text file in which two lines had CR/LF line endings and the other two had LF-only line endings. Then, a small script that reads each line of the file. Following is the business end of it. (All lines in the file have "F" immediately before the line boundary.)

# TWO LINES IN THE FILE MEET THE FOLLOWING CRITERIA: print "ends CRLF\n" if /F\x0D\x0A$/; print "ends CRLF\n" if /F\r\n/; print "contains CR\n" if /\x0D/; print "contains CR\n" if /\r/; # AND THE OTHER TWO LINES IN THE FILE MATCH THIS: print "ends LF only\n" if /F\x0A$/;

But the script printed only this: ends LF only. It never did print ends CRLF or contains CR.

If perl doesn't make some internal translation of the carriage-return characters when it's reading a file, then why that result? Are the tests above not sufficient?

Replies are listed 'Best First'.
(chromatic) RE: Re: Unix \n vs. DOS \n
by chromatic (Archbishop) on Jul 17, 2000 at 01:51 UTC
    chomp returns the number of characters removed. It removes whatever's in $/, so he can just check that.

    Update: Yes, $/, as jlp pointed out.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2022-10-06 19:57 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (28 votes). Check out past polls.