On Mon, Jan 20, 2020 at 02:59 William Michels via perl6-users <
perl6-us...@perl.org> wrote:

> Hi Yary (and Todd),
>
> Thank you both for your responses. Yary, the problem seems to be with
> "get". I can change 'while' to 'for' below, but using 'get' raku/perl6
> actually returns fewer lines with "for" than it did with "while":


If you want to do line-oriented input, use `.lines` with `for`; it returns
something `for` can iterate over.

`.get` is the wrong tool for the job; it returns a single line. To get all
lines, you must call it repeatedly; so you’d need to run an infinite loop
(either using `loop`, `while` with a true value, or `for` with a
never-ending sequence) and break out when you reach the end of the file.

This _works_ just fine, but it’s very weird:

perl6 -e 'loop { last if $*IN.eof; $_ = $*IN.get; .say }' < abc_def.text

You’d typically use “get” in a case where you’re doing low-level I/O, not
for writing a POSIX-like line-oriented filter.  `for lines -> $line { ...
}` is what you want in programs, but `.say for lines` (or put instead of
say, they’re equivalent here) in a one-liner.

>

Reply via email to