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.)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.