Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://949632]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found