By setting $/ to a reference to an integer, you can control how many bytes are read in each use of the diamond operator.
local $/ = \65536;
my $scalar = <FILE>;
print length $scalar;
# prints 65536 (assuming :raw)
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!
Wanted!
| [reply] [d/l] |
In the risk of stating the obvious, I'd like to point out that this is documented in perlvar (search for the section for "$/"). I recall that this is a fairly new addition to Perl, but at least, it is documented to work for perl 5.005_03. So it's not that recent. :)
| [reply] |
Thanks for the tip below. ++
local $/ = \65536;
| [reply] [d/l] |
You can use the sysread function. Try type perldoc -f sysread and read its documentation.
sysread FILEHANDLE, $scalar, $block_size;
The idea is to determine the size of the file with seek and tell, and then keep reading $block_size number of characters into the scalar, in a loop, until there is no more input.
| [reply] [d/l] [select] |
| [reply] |