On Mon, Aug 31, 2020 at 6:07 PM ToddAndMargo via perl6-users
<perl6-users@perl.org> wrote:
>
> 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

dd is the data-dumper function. Used for debugging. See:

https://docs.raku.org/programs/01-debugging#index-entry-dd

Below, you're calling dd on $_ , which is why you don't have/need a
call to print/put/say in that line of code. It's dd() that's giving
you output:

$ raku -e 'dd($_) for "LinesTabs.txt".IO.lines( :chomp, :nl-in["\t"])[1,2,0];'

HTH, Bill.

Reply via email to