Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^3: How can you sysread an entire file?

by esskar (Deacon)
on Jan 12, 2006 at 23:14 UTC ( #522842=note: print w/replies, xml ) Need Help??

in reply to Re^2: How can you sysread an entire file?
in thread How can you sysread an entire file?

try this under windows and linux
use strict; use warnings; open(FILE, '>', '') or die "Daim!"; print FILE "\n"; close FILE;
under windows, the file will have a size of two bytes (\r\n)- under linux just 1 (\n) comapre it to
use strict; use warnings; open(FILE, '>', '') or die "Daim!"; binmode FILE; print FILE "\n"; close FILE;

Replies are listed 'Best First'.
Re^4: How can you sysread an entire file?
by NeilF (Sexton) on Jan 13, 2006 at 18:33 UTC
    I'm aware of that... All my files on Windows & Unix follow that rule... What's the problem?

      I linked to a thread that discusses the bug in the two sentence paragraph in which I mentioned the bug. In some versions of Perl, sysread acts as if binmode is on, even when it's not. When binmode is on, "\n" is not the end of line marker, yet you're splitting on "\n".

      Ok, fine, you won't have a problem in Windows until it's time to chomp, when you'll find the "\r" is not being removed along with the "\n".

        I never do a chomp... Every record keeps its "\n" (at the end) and is written back out with it again.

        I don't plan on splitting the record (variable) while reading - unless there's a good reason. I'll read it all in, then split it on "\n" to put it into an array.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://522842]
[Corion]: And so far I like signatures and nobody has yet come up to me and screamed at me for implementing a source filter to handle them even on early Perl versions ;)
[Corion]: I should re-prod tsee about the Filter::Simple branches that he might want to merge or that I should merge so he can do a release ;-D

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-02-27 14:44 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (388 votes). Check out past polls.