J
J. Romano
Hi,
I was wondering if anyone could tell me the differences between
Perl's read() function and its sysread() function. Now, by reading
the perldocs I know that Perl's read() function implements the
system's fread() call and that Perl's sysread() function implements
the system's read() call, but I really don't know what that means. I
tried reading the man pages on fread() and read(), but that didn't
help me much.
Here is what else I know about read and sysread (please correct me
if I'm wrong):
* read belongs to a group of functions that includes read, print,
write, seek, tell, eof, and the angle-bracket-filehandle-operator.
* sysread belongs to a group of functions that includes sysread,
syswrite, and sysseek.
* The functions in these two groups should not be mixed (unless, as
the Camel book says, I am into wizardry and/or pain). (Just an aside
note: I once accidentally used a print statement on a socket that I
had used sysread() on. It worked fine the first day, but froze up on
the print statement the next day. When I finally found the error and
changed the print statement to syswrite(), the program no longer froze
on me. This was a classic case of "the program worked fine for me
yesterday.")
* The functions open, close, and binmode can be used safely with
functions of both groups.
That's all I know about the difference between Perl's read() and
sysread() functions. What I would still like to know is:
* When should I use read() over sysread() (or sysread() over
read())?
* What differences in program execution can I expect if I switch my
read() statements to sysread() (or vice-versa)?
* If I were to open a socket over the internet using IO::Socket,
would it best to use the read() group of functions or the sysread()
group of functions?
* Since Perl's read() function uses the system's fread() call and
Perl's sysread() function uses the system's read() call, what does
that mean to me if I'm using those functions on a non-Unix system,
like Win32 using ActiveState Perl? I would imagine that, in that
particular circumstance, there would be no difference between Perl's
read() and fread() functions, but the mix-up I mentioned above about
using a print statement with a sysread() function was done on a Perl
program running on a Windows XP machine, so something different must
be happening under the hood even on Win32 operating systems.
Thanks in advance for any input,
Jean-Luc
I was wondering if anyone could tell me the differences between
Perl's read() function and its sysread() function. Now, by reading
the perldocs I know that Perl's read() function implements the
system's fread() call and that Perl's sysread() function implements
the system's read() call, but I really don't know what that means. I
tried reading the man pages on fread() and read(), but that didn't
help me much.
Here is what else I know about read and sysread (please correct me
if I'm wrong):
* read belongs to a group of functions that includes read, print,
write, seek, tell, eof, and the angle-bracket-filehandle-operator.
* sysread belongs to a group of functions that includes sysread,
syswrite, and sysseek.
* The functions in these two groups should not be mixed (unless, as
the Camel book says, I am into wizardry and/or pain). (Just an aside
note: I once accidentally used a print statement on a socket that I
had used sysread() on. It worked fine the first day, but froze up on
the print statement the next day. When I finally found the error and
changed the print statement to syswrite(), the program no longer froze
on me. This was a classic case of "the program worked fine for me
yesterday.")
* The functions open, close, and binmode can be used safely with
functions of both groups.
That's all I know about the difference between Perl's read() and
sysread() functions. What I would still like to know is:
* When should I use read() over sysread() (or sysread() over
read())?
* What differences in program execution can I expect if I switch my
read() statements to sysread() (or vice-versa)?
* If I were to open a socket over the internet using IO::Socket,
would it best to use the read() group of functions or the sysread()
group of functions?
* Since Perl's read() function uses the system's fread() call and
Perl's sysread() function uses the system's read() call, what does
that mean to me if I'm using those functions on a non-Unix system,
like Win32 using ActiveState Perl? I would imagine that, in that
particular circumstance, there would be no difference between Perl's
read() and fread() functions, but the mix-up I mentioned above about
using a print statement with a sysread() function was done on a Perl
program running on a Windows XP machine, so something different must
be happening under the hood even on Win32 operating systems.
Thanks in advance for any input,
Jean-Luc