On 2020-08-30 08:42, yary wrote:
You were close!
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", ....
Now back to the Path lines, which DOES let you specify line endings
methodlines(IO::Path:D::$chomp=True, :$enc='utf8', :$nl-in= ["\x0A",
"\r\n"], |c-->Seq:D)
$ cat line0-10.txt
Line 0
Line 1
Line 2
...
let's pretend that the letter "i" is a line ending.
named arguments can be conveniently written colon pairs :-)
my $nl-in="i"; dd $_ for 'line0-10.txt'.IO.lines(:$nl-in)[0..3];
"L"
"ne 0\nL"
"ne 1\nL"
"ne 2\nL"
How about splitting on either "i" or "\n", and not chomping
my $nl-in=("i","\n"); dd $_ for 'line0-10.txt'.IO.lines(:$nl-in,
:!chomp)[0..3];
"Li"
"ne 0\n"
"Li"
"ne 1\n"
To put in line endings without having a variable of the same name as the
naed arg, use the full form of the colon pair
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,
Now what am I doing wrong?
p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:nl-in["\t", 0x09],
:!chomp) {dd $_};'
Str $x = "a\tb\tc\td\t"
"a\tb\tc\td\t"
:'(
-T