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

During the course of my day i had to parse and process at 2m+ line text file. No worries i thought:
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.