ansh007:
The problem with memory is that you're reading all the lines of the file at once. Rather than doing that, read the file line by line and do your processing. That way you can handle a file of any size. You can do so like this:
# The three-argument version of open, and using lexical variables is p
+referred
open my $LOG_READ, '<', $InLogFilePath or die "Can't open file $InLogF
+ilePath: $!";
# Read the next line into $current_line
while (my $current_line = <$LOG_READ>) {
# Ignore the first $InStartLineNumber lines of the file
next if $. < $InStartLineNumber;
# Process current line
. . .
}
close $LOG_READ;
As you'll notice, I intentionally changed the way you did things:
There's no real need to spawn two additional processes to perform tasks that perl can already do for you. Especially not to:
- Earn a "useless use of cat" award.
- Use tail to ignore some of your input file, a task perl is perfectly capable of itself.
The three-argument form of open is safer than the old two-argument open.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
-
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.
|