> Hmmm. I would expect that to be in the Perl 5 to Perl 6 Migration Guides, but
> I do not see it there.
Exactly, I was just looking there, and I ended up playing around with
the method form of lines, and didn't think to try the function
form of it.
To summarize, if the goal is to write a "simple_echo" script that
can work with a file name or with lines on standard input:
simple_echo lines.txt
cat lines.txt | simple_echo
The perl5 version would probably be:
#!/usr/bin/env perl
while(<>){
print;
}
The perl6 version would be something like:
#!/usr/bin/env perl6
use v6;
for lines() {
say $_;
}
The kind of thing I was playing with was:
#!/usr/bin/env perl6
use v6;
my @lines = $*ARGFILES.IO.lines;
say @lines;
That works for lines from a file, but not from standard input, and the
error message isn't tremendously helpful:
No such method 'lines' for invocant of type 'IO::Special'
On 7/28/19, Bruce Gray <[email protected]> wrote:
>
>
>> On Jul 28, 2019, at 6:20 PM, Joseph Brenner <[email protected]> wrote:
>>
>> I was just wondering if there's some direct analog in perl6 to the
>> perl5 construct:
>>
>> while(<>){ ... }
>>
>> If I'm planning on passing a filename on the command-line, I can just
>> get it out of $*ARGFILES easily enough, but what if I also wanted it
>> to work on lines passed in via standard input?
>
>
> `lines` , as a sub instead of a method, and no arguments.
>
> See: https://docs.perl6.org/routine/lines#(Cool)_routine_lines
> Without any arguments, sub lines operates on $*ARGFILES, which defaults
> to
> $*IN in the absence of any filenames.
>
> For example:
> perl6 -e 'say .join("\t") for lines().rotor(4);' path/to/file.txt
>
> Hmmm. I would expect that to be in the Perl 5 to Perl 6 Migration Guides,
> but I do not see it there.
>
> —
> Hope this helps,
> Bruce Gray (Util of PerlMonks)
>
>