Solved

** READ vs SYSREAD: Difference?? **

Posted on 1998-01-06
4
563 Views
Last Modified: 2012-06-27
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
Comment
Question by:ljaques
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1209493
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
 
LVL 1

Accepted Solution

by:
gabsi earned 10 total points
ID: 1209494
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
 

Author Comment

by:ljaques
ID: 1209495
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
 

Author Comment

by:ljaques
ID: 1209496
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question