A rather direct translation:
for lines() {
# .=chomp;
print join("\t", .split(':')[0, 2, 1, 5] ), "\n";
}
Note that for `.=chomp` to work, you probably have to declare `$_` as `is
copy`.
for ("a\n", "b\n") -> $_ is copy {
.=chomp;
print join("\t",
My guesses at Perl 6 versions of the Perl 5 example:
say .split(':')[0, 2, 1, 5].join("\t") for lines;
-or-
for lines { say .split(':')[0, 2, 1, 5].join("\t") }
Pm
On Mon, Jul 29, 2019 at 12:49:51PM -0700, William Michels via perl6-users wrote:
> Hello, Just a short backgrounder to say
Hello, Just a short backgrounder to say that this question arose this
past weekend at a Perl6 Meetup (Oakland, CA). Specifically we were
looking at how to write a Perl6 version of some introductory Perl5
code in "Learning Perl", 7th Edition by Tom Phoenix, brian d foy,
Randal L. Schwartz:
#Perl 5
Also, you can make this conditional: show me all the comment lines of a source
file:
$ perl6 -e '.say if .starts-with('#') for lines' source-file
> On 29 Jul 2019, at 10:06, Richard Hainsworth wrote:
>
> Also no need for all the brackets
>
> .say for lines;
>
> This is quite idiomatic
Also no need for all the brackets
.say for lines;
This is quite idiomatic Perl 6 and not golfing
On Mon, 29 Jul 2019, 07:13 Joseph Brenner, wrote:
> > 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,
In Perl 6, you also don't need to explicitly use $_ in this case if
you use the method form of say.
for lines() {
.say
}
On Sun, 28 Jul 2019 23:13:08 -0700
Joseph Brenner wrote:
> [...]
>
> The perl6 version would be something like:
>
> #!/usr/bin/env perl6
> use v6;
>
> 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