in reply to Re: Simple query regarding unpack/splice
in thread Simple query regarding unpack/splice
Update: BTW this is a bad idea: while (read(FILE, $buf, $recsize) == $recsize) {However, if you do get a short read, do you really want to perform the unpack?
You can always detect a short read by checking the length of $buf at the end of the loop:
When reading from a disk file (that no one else is writing to), the only place you'll get a short read is at the end of the file. This isn't true for a pipe or a socket where there are more circumstances that will give you a short read before you've reached eof.while (...) { } if (length($buf) > 0 && length($buf) < $recsize) { # last read was short }
|
|---|