Eating memory

Luke Ross luke at
Tue May 23 09:39:36 BST 2006


On Tue, May 23, 2006 at 12:53:05PM +0100, Simon Wilcox wrote:
> foreach (<INFILE>) {
> }

Your problem is here. The file is read into memory as an array of lines, 
which foreach steps over. You need to use:


which does what you want, as it's short for:

while (defined($_ = <INFILE>))

The scalar assignment means only one line is read from INFILE on each 

``Ladies & Gentleman, upon departing the train may I remind you to take your
  rubbish with you. Despite the fact that you are in something that is metal,
  fairly round, filthy and smells, this is a tube train for public transport
  and not a bin on wheels'' (A LU tube train driver)

More information about the mailing list