So, trying to put this together: It appears the combination of assigning the text to the variable ("$strings = <FILE>"), followed by the script, continuing to run (via the infinite loop), that can re-use the contents of $strings as many times as required, is the essence of the mechanism to avoid re-reading the file...
Not really. For one thing you have a mistake (repeated twice) which may be a typo but which is also substantial, so I'm pointing it out: it's not $strings, but @strings! The difference is that the former on the lhs of an assignment imposes scalar context. Thus $strings = <FILE> puts into $strings a single "line". Now, I write "line" in double quotes because it may even be the whole file, as a single string, depending on the input record separator ($/ - look it up in perldoc perlvar). For simplity let's assume that the latter has not been changed from the default and that lines are actually lines: when you do @strings = <FILE> you're in list context instead and each element of the @strings array is a line. Then you iterate over it as over any other list. That's it.
Let's move on: perhaps a bigger and more severe misunderstanding on your part is with the infinite loop: that has nothing to do with looping over @strings, it is orthogonal. Indeed the latter is nested in the former: here you have two loops one within the other, the second of which disguised as a grep.
In all earnestness, I'm not familiar with the Llama book, but if this is its final exercise I must presume you've gone through all of it and please don't take it as a personal offense, but I find it a bit surprising that you're still doing all this confusion...
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||