On 2020-08-31 17:21, yary wrote:
First part of my previous email on this thread! Re-read this bit
First, you were looking at the docs for Path's "lines", but you are
using a string "lines" and those docs say
multi method lines(Str:D: $limit, :$chomp = True)
multi method lines(Str:D: :$chomp = True)
Files get "nl-in" due to the special case of text files having various
line endings to tweak.
Strings already have "split" and "comb" for all the flexibility one may
need there, and what you're playing with is more naturally
dd $_ for $x.split("\t"); # "a","b", ... removes \t
dd $_ for $x.split(/<?after \t>/); "a\t","b\t", ....
and restating the above: "string".lines is different a different method
from "File.txt".IO.lines, which is also different from
"File.txt".IO.open.lines . Yes that's confusing but there are reasons
for all that which make sense when one thinks about them a while.
So if you want to split a string, use split!
If you want to experiment a text file's line endings with "lines", do
that experiment with a file! Which was the 2nd part of my previous email
dd $_ for 'line0-10.txt'.IO.lines(:nl-in["i","\n"], :!chomp)[0..3];
"Li"
"ne 0\n"
"Li"
"ne 1\n"
-y
Hi Yary,
I think I am getting it. I am confusing str with file.
In the following, LineTabs.txt is
"Line 1\tLine 2\tLine 3\tLine 4\t"
$ raku -e 'dd $_ for "LinesTabs.txt".IO.lines( :!chomp,
:nl-in["\t"])[1,2,0];'
"Line 1\t"
"Line 2\t"
"Line 0\t"
$ raku -e 'dd $_ for "LinesTabs.txt".IO.lines( :chomp,
:nl-in["\t"])[1,2,0];'
"Line 1"
"Line 2"
"Line 0"
I am having trouble wrapping my mind around `dd $_ for`. What
exactly is going on?
-T