Solved

** READ vs SYSREAD: Difference?? **

Posted on 1998-01-06
4
578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans

691 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