in reply to What happens to the bytes not read by read() ?
This test indicates the data is still available for additional reading.
use strict; use warnings; my $data; my $bytes = read( DATA, $data, 10 ); print "read $bytes bytes: [$data]\n"; # read 10 bytes: [1234567890] $bytes = read( DATA, $data, 5 ); print "read $bytes bytes: [$data]\n"; # read 5 bytes: [abcde] __DATA__ 1234567890abcdefg
Update: As mentioned in the docs, read returns the number of bytes actually read, 0 at end of file, or undef if there was an error. This means you can loop until read returns false:
use strict; use warnings; my $data; while( read( DATA, $data, 5 ) ) { print "[$data]\n"; } __DATA__ Just another Perl hacker,
This prints
[Just ] [anoth] [er Pe] [rl ha] [cker,]
|
|---|