| [reply] |
I think that you use twice the memory in the version where $foo is assigned the results of the do{} block because you have the memory for the return value of the do{} block and the memory for the contents of $foo in use at the same time, so that you can copy from one to the other. Both contain a full copy of the whole file.
In the version where $foo is assigned to from within the do{}, you just have the $foo variable to hold the whole file, since it is assigned to in chunks from the file buffer. There is no other space allocated to hold the contents returned by the do{} block because the value of the do{} is not assigned to anything. Thus only one copy of the whole file has to be held in memory at one time.
That's the way I read it anyway.
| [reply] |
That may be the case but it's wrong behaviour on the part of the interpreter. The value being returned should be marked as a temporary and should be able to be re-used by the next part of the expression. It shouldn't be copied. If it is, that's a bug. Perl is supposed to be good at this kind of thing.
| [reply] |
| [reply] |