** 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?
ljaquesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.