Solved

** READ vs SYSREAD: Difference?? **

Posted on 1998-01-06
4
550 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now