Maybe this is what you want?

~$ raku -e 'say "test_lines.txt".IO.lines;'
(Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11)

~$ raku -e 'say "test_lines.txt".IO.lines.join("\n");'
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11

~$ raku -e 'say "test_lines.txt".IO.lines[3,2].join("\n");'
Line 4
Line 3

~$ raku -e 'say "test_lines.txt".IO.lines[ (3,2).map(*-1) ].join("\n");'
Line 3
Line 2

By default, Raku strips new lines off when reading data in, and adds
newlines back on when outputting with "say" or "put" (but not
"print"). Using "WHAT" you can get an idea how Raku behaves
differently depending on whether you call "IO.lines" or "for lines()"
on an input file:

~$ raku -e '"test_lines.txt".IO.lines.WHAT.say;'
(Seq)

~$ raku -e '"test_lines.txt".IO.lines[3,2].WHAT.say;'
(List)

~$ cat "test_lines.txt" | raku -e 'for lines()[3,2] {.WHAT.say};'
(Str)
(Str)


HTH, Bill.





On Sat, Aug 29, 2020 at 10:15 PM ToddAndMargo via perl6-users
<perl6-users@perl.org> wrote:
>
> Hi All,
>
> I am trying to figure out how to use line with :$chomp.
> Now what am I doing wrong?
>
>
> $ alias p6
> alias p6='perl6 -e'
>
> $ p6 'say "Lines.txt".IO.open.lines(:chomp)[3,2];'
> (Line 3 Line 2)
>
> $ p6 'say "Lines.txt".IO.open.lines(:!chomp)[3,2];'
> (Line 3 Line 2)
>
> I am looking for
>
> Line 3
> Line 2
>
> Many thanks,
> -T

Reply via email to