-
Sysread may return a parital result (that is, read less characters then requested) any time. Indeed, it must return exactly one packet with datagram sockets like udp.
Read cannot do that except at the end of file.
-
Sysread bypasses buffering, and also perlio layers to some extent.
-
Update: sysread cannot be tied.
-
Possibly more I don't know about.
As a general rule, use read unless you have a reason to use sysread.
| [reply] |
buffered or unbuffered, using or not using stdio
read:
Fixed-length buffered input from a filehandle
read FILEHANDLE,SCALAR,LENGTH,OFFSET
read FILEHANDLE,SCALAR,LENGTH
Attempts to read LENGTH bytes of data into variable SCALAR from the specified FILEHANDLE. Returns the number of bytes actually read, 0 at end of file, 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. This call is actually implemented in terms of stdio's fread call. To get a true read system call, see sysread().
sysread:
sysread function
Fixed-length unbuffered input from a filehandle
sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
sysread FILEHANDLE,SCALAR,LENGTH
Attempts to read LENGTH bytes of data into variable SCALAR from the specified FILEHANDLE, using the system call read. It bypasses stdio, so mixing this with other kinds of reads, print(), write(), seek(), or tell() can cause confusion because stdio usually buffers data. Returns the number of bytes actually read, 0 at end of file, or undef if there was an error. SCALAR will be grown or shrunk so that the last byte actually read is the last byte of the scalar after the read.
An OFFSET may be specified to place the read data at some place in the string other than the beginning. A negative OFFSET specifies placement at that many bytes counting backwards from the end of the string. A positive OFFSET greater than the length of SCALAR results in the string being padded to the required size with "\0" bytes before the result of the read is appended.
| [reply] |
from perldoc -f read
The call is actually implemented in terms of stdio's fread(3) call. To get a true read(2) system call, see "sysread".
Manav
| [reply] |