On Fri, Jun 05, 2009 at 01:39:02PM +0200, Carl Mäsak wrote:
: Daniel (>), Leon (>>), Daniel (>>>):
: >>> Then why is it that .get works fine for $*IN?
: >>>
: >>> while $*IN.get -> $line {
: >>>       say $line
: >>> }
: >>>
: >>
: >> Because you're using a while loop instead of a for loop ;-)
: >
: > Worse. The code I wrote has a subtle but horrible error. The condition will
: > fail as soon as you hit a blank line!!
: Which, I think, summarizes why the 'for $*IN.lines' idiom is preferred
: in Perl 6.

Indeed, that preference is why Perl 6 can (we hope) get away with
autochomping, where Perl 5 can't (as easily).  Or more accurately,
we choose not to special-case "while (<>)" as Perl 5 does (because
even Perl 5 has difficulties with files that are accidentally
"autochomped" by omitting the final newline in the file).

But we're trying very hard to get rid of most such special cases in
Perl 6.  Usually we can get the recommended Perl 6 code to just DWYM
as a fallout of the general semantics, but in this particular case,
if you really want to read your input with while, there's a slight
"regression" from Perl 5 insofar as you must explicitly use defined().
This de-huffmanization is intended as a subtle encouragement to move
from Item-Think towards List-Think.  :)


Reply via email to