open(FH, 'someLargeFile.txt') || die "Unable to open file: $!"; foreach (<FH>) { .. #do something }
I thought this would loop thru each line of the file and #do something. I was wrong, and of course i felt like a bit of a n00b.
What i saw happening on my little sparc was the entire file being loaded into memory, then being processed, and because it was so large, it didnt fit, and abended.
So being an "experienced n00b" i tried a couple of things and found out that if i s/foreach/while/ it seems to iterate over everything without loading it all into memory 1st.
When i think about it, it kinda makes sense, in that how can foreach know when to stop, when it doesnt know where the end is, and while its just going until it finds an EOF marker.
Moral of the story, if something is not working as you expected, its probably not designed to, _or_ you can think you've got experience in things, you probably have, but the basics can still jump up and bite.
n00bily yours...
Update: as pointed out by gmax jargon can sometimes be difficult. in this case n00b == newbie == someone new to doing something.
|
---|
Replies are listed 'Best First'. | |
---|---|
•Re: file processing, while and foreach: a n00b experience
by merlyn (Sage) on Aug 27, 2003 at 13:06 UTC | |
Re: file processing, while and foreach: a n00b experience
by Juerd (Abbot) on Aug 27, 2003 at 09:08 UTC | |
by Aristotle (Chancellor) on Aug 28, 2003 at 12:12 UTC | |
by John M. Dlugosz (Monsignor) on Sep 02, 2003 at 20:39 UTC | |
Re: file processing, while and foreach: a n00b experience
by broquaint (Abbot) on Aug 27, 2003 at 09:09 UTC | |
Re: file processing, while and foreach: a n00b experience
by wirrwarr (Monk) on Aug 27, 2003 at 12:20 UTC |