A bug? or lack of a feature?
The temporary value in question is and array, potentially a very big array. It's not ready to pass up to the next level until it's all there. Yes one could pass it up a piece at a time, in a queue, like the unix shells do with pipes, but that brings the overhead of monitoring the (those) process(es), and distinguishing from the case where you want to collect everything together and then proceed.
It is a good idea, and it's what lazily evaluated lists are about in Perl6, see Apolalypse 6. The neat thing there is that you can even assign a lazy list to a variable, and not have to deal with getting to the end of the list until you use it. (Just don't ask for it's length up front.) | [reply] |
You're misundersanding. The entire value is stored at once in a temporary variable known only on a padlist. The next operation, the scalar assignment, should utterly consume the temporary value during its use instead of making a copy just for it's own purposes. There should only be one copy of the data during this entire process. This is a perl5 thing, not a perl6 thing. I'm only speaking about perl5 internals.
| [reply] |
Your quite right, I got muddled thinking about the records coming back and being passed up, but the whole point of the OP was to put the entire file into a scalar. Lists, lazy or otherwise, have nothing to do with it.
Let's see if I've managed to get this through my somewhat thickening skull. (And to move down a level of abstratction).
- The file is opened within the do{} loop, and records are transfer to a temporary scalar variable
- The file finishes. The do{} loop passes the temporary back to the assignment
- The compiler has recognized (using the code tree?) that the temporary is only going to the assigned to a variable, $foo, and the $foo SV is set to point to the data from the temp SV; the temp SV is now available for the next use. Thus the data exists only once.
At least that's the way it's supposed to work, so the additional memory usage observed by Grandfather shouldn't happen.
Let me know if I've gotten this significantly wrong. (And thanks for the corrections, and your patientce when I got lost.)
| [reply] |