Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 593
  • Last Modified:

** READ vs SYSREAD: Difference?? **

So what's the difference between SYSREAD/READ and WRITE/SYSWRITE functions?

One thing I've only noticed is that on my PC Windows 95 (in DOS) Perl doesn't seem to want to work with the WRITE function.  I've got to use SYSWRITE or PRINT OUT just to get  a write to disk. I think I;ve read somewhere that SYSREAD/SYSWRITE are way faster for accessing the disk.  If this is the case then why bother with the other 2 functions?!

Is there maybe a compatiblity problem with Unix/WinNT?
0
ljaques
Asked:
ljaques
  • 2
1 Solution
 
ozoCommented:
Perl doesn't have SYSREAD/READ and WRITE/SYSWRITE functions.
It has a write function, which does formatted writes.
Are you using formats?  
If so, write is what you want, otherwise, use print for simple string output.
sysread and syswrite are calls to the POSIX read and write functions,
so you have to handle things like partial writes or interupted system calls yourself.
The perl read and print functions handle those things for you.
Perl's read uses the fread system call and handles its own buffering,
so you shouldn't try to mix read and sysread or print and syswrite
calls on the same file handle unless you know what you're doing.


0
 
gabsiCommented:
sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
OR
sysread FILEHANDLE,SCALAR,LENGTH
Attempts to read LENGTH bytes of data into variable SCALAR
from the specified FILEHANDLE, using the system call read(2).
It bypasses stdio, so mixing this with other kinds of reads
may cause confusion.  Returns the number of bytes actually
read, or undef if there was an error.  SCALAR will be grown or
shrunk to the length actually read.  An OFFSET may be
specified to place the read data at some other place than the
beginning of the string.
0
 
ljaquesAuthor Commented:
All I do is open a filename for output and try to write my data to disk.  But when I do so using the WRITE command it writes nothing to disk?!  When i use the SYSWRITE command it works just fine.  The PRINT OUT command also works fine.

I am using Perl 5 for my PC under Win95.  It has SYSREAD and SYSWRITE.  You make the SYSREAD/SYSWRITE sound deadly!  The regular READ function works but can you tell me why doesn't the regular WRITE function work?  I need to use it.  I'm just writing a line of bytes to disk all crammed right next to one another.

And what's formatting?

Thanks ozo!
0
 
ljaquesAuthor Commented:
And when you say "mixing" read functions with SYSREAD and cause confusion since the SYSREAD bypasses the stdio what do you mean?  DO you mean don't use the regular READ function or fgetc or something like that, only stick with SYSREAD, and the same goes with SYSWRITE??

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now