in reply to Out of memory

That's because you want to read in the entire file into memory - while doing it in an inefficient way.

Why not count the number of words on a line by line basis? BTW, your regex /[ +\n+\,\:]/ isn't doing what you think it's doing.

Abigail

Replies are listed 'Best First'.
Re: Re: Out of memory
by Anonymous Monk on Aug 19, 2002 at 12:17 UTC
    Hi,

    Thanks for the reply.

    That was precisely my question . I guess there are more efficient ways of reading the file that would alleviate my memory problem - and that's where I need the help. What other ways can I read it in?

    Also, u got me scared about the regex /[ +\n+\,\:]/ bit. I thought I was splitting on space/s , newline/s, comma and colon. Am I not ? I'm a Perl novice and any suggestions are much appreciated.

    Thanks
    J

      Oh, you are reading it in fine - line by line. But then you join all the lines together until you have read all the lines, before you count the words.

      Why not count the words of the line just read, and then read in the next line?

      As for your regex, you split on a space, a plus, a newline, a plus (again), a comma or a semi-colon. I think you want: /[\s,:]+/.

      Abigail