Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Answer: How do I read an entire file into a string?

by BrowserUk (Pope)
on Jun 15, 2016 at 00:22 UTC ( #1165670=note: print w/replies, xml ) Need Help??


in reply to Answer: How do I read an entire file into a string?
in thread files

I noticed that the "end-of-line" for each line is changed from "0d 0a" to "0d 0d 0a"

Windows converts 0x0a to 0x0d 0x0a on output unless the output file handle has been marked binary (as with binmode).

On input, it does the reverse, converting 0x0d 0x0a to 0x0a; if the file hasn't been marked binary..

What is happening in your case is that when the text file is written, 0x0a becomes 0x0d 0x0a. When you read it in as binary, no conversion is done so you get 0x0d 0x0a in memory...

But when you print it to the text mode screen, the automatic conversion is done (again), so 0x0d 0x0a becomes 0x0d 0x0d 0x0a as you are seeing.

When you omit the binmode, the 0x0d 0x0a read from disk, become just 0x0a in memory; and then when you print it out, they get converted back to 0x0d 0x0a and everything looks normal.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.
  • Comment on Re: Answer: How do I read an entire file into a string?

Replies are listed 'Best First'.
Re^2: Answer: How do I read an entire file into a string?
by Discipulus (Monsignor) on Jun 15, 2016 at 07:41 UTC

      Discussion about chomp doesn't explain the binmod problem. It's related, but really quite separate.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1165670]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2017-12-13 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (361 votes). Check out past polls.

    Notices?