Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^7: Dealing with files with differing line endings

by haukex (Bishop)
on Nov 15, 2021 at 21:21 UTC ( #11138854=note: print w/replies, xml ) Need Help??


in reply to Re^6: Dealing with files with differing line endings
in thread Dealing with files with differing line endings

when reading a line using "<:raw", Perl is looking for a LF to determine the "end of line"

It's looking for $/.

chomp() only operates on LF, not CRLF.

chomp operates on whatever $/ is set to, including if that's set to CRLF for whatever unusual reason.

When reading a Windows file on Unix, the I/O layer zaps the CR and I never see it.

Only if you explicitly specify the :crlf layer, which your code doesn't do.

The terminology does get confusing because "\n" as written in Perl on Windows sometimes means CRLF and sometimes it means only LF.

For about the millionth time: No. Maybe it's finally time to read Newlines in perlport?

Replies are listed 'Best First'.
Re^8: Dealing with files with differing line endings
by pryrt (Monsignor) on Nov 15, 2021 at 22:08 UTC
    Only if you explicitly specify the :crlf layer, which your code doesn't do.

    Strawberry perl.exe adds the :crlf layer unless you tell it otherwise.

    C:\usr\local\share>perl -MConfig -MPerlIO -le "print for PerlIO::get_l +ayers(STDIN), '-'x10, $Config{myuname}" unix crlf ---------- Win32 strawberry-perl 5.30.0.1 #1 Thu May 23 12:20:46 2019 x64

    (I haven't used Active State since the early aughts, so I cannot tell you how the other major Windows port of perl behaves, though my vague recollections were that I had never heard of IO layers back then, but that newlines just worked right, as they do with modern Strawberry, so I am assuming they also set :crlf for you.)


    update: hmm, you even knew it was on by default on Windows in Re^9: How do I display only matches (from the other conversation you alluded to), so I have to assume I've missed something in the context of this thread. I don't see anything in the posted code that would override that (other than the :raw open, of course)... so I'm more confused than when I first posted this. :-( Maybe I've had too hard of a day, and I should stop trying at this point. Time to go home! :-)
      I have to assume I've missed something in the context of this thread.

      This bit in the text I quoted:

      When reading a Windows file on Unix

      It happens :-) And though it's just a guess, I'd be surprised if ActivePerl doesn't add the :crlf layer by default. I think Cygwin Perl doesn't.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2022-01-20 23:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?