Re: Re: Generators in PHP
| From: | Lester Caine | Date: | Sat, 28 Jul 2012 07:37:13 +0000 |
| Subject: | Re: Re: Generators in PHP | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-61855@lists.php.net to get a copy of this message | ||
Rasmus Lerdorf wrote:
Exactly ... when uploading the NLPG csv files I process them line at a time and store to the database. I always have ... which is why I don't recognise the initial 'complaint' that justified adding this. These files can be 100Mb+ so there is no way one would process them by reading the whole lot in as the 'example' gave. You just call the function that processes the particular type of line which is based on the first two characters ... after reading the line. -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.ukIt's this 'concept' that I am having trouble seeing in the general process that is required using PHP to generate web pages. At the end of the day I have to generate the finished page or sub-page so I need all the results anyway. Sure, but that doesn't mean it has to all be in memory at the same time. You can read lines from a large file line-by-line, process that line and output the result before you move onto the next line.I don't think this generator question is any different. We need toexplain generators in the simplest way possible. The simplest way to explain generators is to not even worry about them being generators at all. Simply say that functions can now return arrays one element at a time using the new yield keyword. That's all.