If you are going to be processing megabytes of data or more then it is probably a good idea to buffer chunks of it into RAM as it is *much* faster than processing it line by line using IO. If you plan buffering then I recommend something like this
{
# NOTE: code is untested
my @chunks = ();
local $/ = \102400;
while(<$fh>) {
my $chunk = $_;
my $last_rs = rindex($chunk, $/)
push @chunks, substr($chunk, 0, $last_rs);
seek($fh, 1, -(length($chunk) - $last_rs));
}
}
This should read up to 100k chunks at a time but also making sure the chunk ends on a new line. As far as I'm aware there are no buffering modules like you describe (at least a quick
CPAN search doesn't seem to turn anything up) so perhaps it's time to write one?
HTH
_________
broquaint
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.