Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Request to detect the mistake in a perl script for finding inter-substring distance from a large text file

by rovf (Priest)
on Jan 24, 2012 at 10:02 UTC ( #949632=note: print w/ replies, xml ) Need Help??


in reply to Request to detect the mistake in a perl script for finding inter-substring distance from a large text file

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>


Comment on Re: Request to detect the mistake in a perl script for finding inter-substring distance from a large text file
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://949632]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2014-12-23 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (134 votes), past polls