in reply to How to process each byte in a binary file?

for large files...

my $file = 'myverylargefile.bin'; { local *INPUT; local $/ = \1; open INPUT, '<', $file or die $!; while(<INPUT>) { ## process here... } }
from pervar:
Setting $/ to a reference to an integer, scalar containing an integer, or scalar that's convertible to an integer will attempt to read records instead of lines, with the maximum record size being the referenced integer.

~Particle *accelerates*

Replies are listed 'Best First'.
Re: Re: How to process each byte in a binary file?
by John M. Dlugosz (Monsignor) on Aug 12, 2002 at 21:16 UTC
    It looks like $/ doesn't have any effect on IO::Scalar. I see that if the input is already in a file, and really is a primitive file handle, that this saves the trouble of reading it in first. But I wonder if the overhead of one read at a time is still high, compared to reading a chunk at a time and processing the chunks using one of the other methods.