http://qs321.pair.com?node_id=949632


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