Peter Xu wrote:
John W. Krahn wrote:
perldoc -f sysread
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(2). It bypasses buffered IO, so mixing this with other
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
kinds of reads, "print", "write", "seek", "tell", or "eof"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
can cause confusion because the perlio or stdio layers
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
usually buffers data. Returns the number of bytes actually
^^^^^^^^^^^^^^^^^^^^^
read, 0 at end of file, or undef if there was an error (in
the latter case $! is also set). SCALAR will be grown or
shrunk so that the last byte actually read is the last byte
of the scalar after the read.
You want to use read instead:
perldoc -f read
Thanks, John, I got it.
Actually, I have read the perldoc of sysread(), I just didn't really
understand the "truth" of the read buffer. And also, I didn't totally
realized that, <$file> is a read()!
Actually <$file> is short for readline( $file )
perldoc -f readline
read() is more like sysread() than it is like readline().
After your tutor, I also tried this in a bigger "test.txt" file, which
made me more clear about the situation I think.
--------------------------------
...
my $tmp = <$file>;
print "the unbuffered index : ", sysseek($file, 0, 1), "\n";
Instead of using "1" for the WHENCE argument you should use the ':seek'
constants provided by the Fcntl module.
perldoc Fcntl
print "the buffered index : ", tell($file), "\n";
...
--------------------------------
it outputs:
--------------------------------
the unbuffered index : 1240
That number doesn't look right. Unfortunately I can't reproduce your
results as I don't use Windows.
the buffered index : 7
--------------------------------
which also showed the buffered size of read().
Thanks again!
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/