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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|