Hm, well, then, here's an alternate approach that does away with a subroutine. I assume the goal is to avoid loading a large file willy nilly into a Perl scalar (because read is already buffered):
- Work out the total # of bytes to read.
- Work out how many chunks of $bufsiz that would need to be read.
- Work out the remaining # of bytes
- print out a sufficient # of big chunks
- print out the last chunk
Some code (totally off the top of my head, untested, just to give the idea):
# get $start, $end
my $bufsiz = 4096;
my $total_length = $end-$start;
my $chunks = int $total_length / $bufsiz;
my $data;
if ($chunks) {
foreach (1 ... $chunks) {
read (FILE, $data, $bufsiz);
print $data;
}
}
read (FILE, $data, $total_length % $bufsiz);
print $data;
Philosophy can be made out of anything. Or less -- Jerry A. Fodor
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.