my @lines = <DNAFILE>;
while (<DNAFILE>) {
say $_;
}
This piece of code doesn't make sense. First, you read the *whole* file into memory (storing it at @lines), and then you try to read another line (your while loop), which is, of course, not possible. Your loop won't be executed; you can remove it without harm.
But the main problem is that you read the whole file into memory and process it from there. No wonder that your memory gets exhausted sooner or later (try to pour a whole bottle of beer into a coffee cup; unless the cup is really huge, you will spill some beer).
Maybe Tie::File will help you as a first start. It allows you to treat the whole file as an array, without slurping it into memory. Be aware that, possibly, the runtime of your application will increase.
--
Ronald Fischer <ynnor@mm.st>
-
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.
|