Here is a snippet from some code that I wrote "many moons ago". This code will run not just a "little bit" faster than a Win command line...the performance difference is HUGE, even with just 8K buffer. If the search in the buffer can be run with say just two of these 8K buffers, it will be very, very fast. This is a copy routine, but same principle works for reading large files.
showfailed() is a tricky thing that is sort of like die() and warn() and has a GUI display context. For the purpose here, it doesn't even matter.
##################
# Binary File Copy and Append
#
# bcopy($output, @input_files);
# # first element is the output file path,
# # then input files: file1, file2...file n.
sub bcopy()
{
(my $out, my @in_list)=@_;
open (OUTBIN, ">", "$out") || showfailed
("unable to open $out");
binmode(OUTBIN) || showfailed
("unable to set binmode $out");
foreach my $infile (@in_list)
{
open(INBIN, "<", "$infile")|| showfailed
("unable to open $infile");
binmode(INBIN) || showfailed
("unable to set binmode $infile");
while (read(INBIN, my $buff, 8 * 2**10))
{
print OUTBIN $buff;
}
close(INBIN) || showfailed("unable to close $infile");
print "$infile appended to $out\n";
}
close(OUTBIN) || showfailed("unable to close $out");
} #end of bcopy
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.