$file.IO.lines( :nl-in(…), :chomp, … ) is actually short for
$file.IO.open( :nl-in(…), :chomp ).lines( … ) On Sun, Aug 30, 2020 at 10:43 AM yary <not....@gmail.com> 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 > > method lines(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 > > > On Sun, Aug 30, 2020 at 2:58 AM ToddAndMargo via perl6-users < > perl6-users@perl.org> wrote: > >> Hi All, >> >> https://docs.raku.org/type/IO::Path#method_lines >> >> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = >> ["\x0A", "\r\n"], |c --> Seq:D) >> >> How do I change what lines sees as a new line. Is it >> :$nl-in? A tab in this case. >> >> Some of my missteps: >> >> $ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, "\t") {dd $_};' >> Str $x = "a\tb\tc\td\t" >> >> >> $ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, :$nl-in = >> ["\x0A", "\r\n"]) {dd $_};' >> ===SORRY!=== Error while compiling -e >> Variable '$nl-in' is not declared >> at -e:1 >> ------> tc\td\t"; dd $x; for $x.lines(:!chomp, :⏏$nl-in = ["\x0A", >> "\r\n"]) {dd $_}; >> >> $ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, :nl-in = >> ["\x0A", "\r\n"]) {dd $_};' >> Str $x = "a\tb\tc\td\t" >> Cannot modify an immutable Pair (nl-in => True) >> in block <unit> at -e line 1 >> >> >> Many thanks, >> -T >> >