Expanding on how to read the docs & signature a bit, from Tobias > You confuse two methods that have the same name "lines". One of them, > which exists in the IO::Path class, has a :chomp argument. The other, > on IO::Handle does not. > "path".IO.lines() <-- calls lines on an IO::Path (supports :chomp) > "path".IO.open.lines() <-- calls lines on an IO::Handle (does not > support :chomp)
Looking up https://docs.raku.org/routine/lines shows a Table of Contents with class Cool (Cool) routine lines class Supply (Supply) method lines class Str (Str) routine lines class IO::CatHandle (IO::CatHandle) method lines class IO::Path (IO::Path) method lines class IO::Handle (IO::Handle) routine lines class IO::Socket::INET (IO::Socket::INET) method lines Lots of different "lines" methods. If I click on IO::Handle it jumps to sub lines( $what = $*ARGFILES, |c) multi method lines( IO::Handle:D: $limit, :$close ) multi method lines( IO::Handle:D: :$close ) which indeed has no named argument for "chomp" As an aside-Reading between the lines (no pun intended), I deduce that the IO::Handle "lines" method is its own implementation so that it can read "lazily" as needed, and to support the "close" option. And as another aside, it has a "sub" which shows that when "lines" is called with no arguments, it defaults to reading from $*ARGFILES. So, back to the table of contents. How does one know which "lines" routine to look at? Either by thinking & remembering -- "oh 'file'.IO.open returns an IO::Handle that's the one to read" "Huh 'file'.IO returns a path object, and there's *'(IO::Path) method* *lines'* listed lets look at that, hmm it has *chomp*" or by experiment! > 'example.txt'.IO.WHAT (Path) > 'example.txt'.IO.open.WHAT (Handle) -y On Sun, Aug 30, 2020 at 12:56 AM ToddAndMargo via perl6-users < perl6-us...@perl.org> wrote: > On 2020-08-30 00:35, Tobias Boege wrote: > > On Sun, 30 Aug 2020, ToddAndMargo via perl6-users wrote: > >>> - You are calling .lines on the value of .IO.open which is an > >>> IO::Handle. IO::Handle.lines does not take a named argument > >>> :chomp, so passing one is useless. > >> > >> That explains it. > >> > >> Butttttttt: > >> https://docs.raku.org/type/IO::Path#method_lines > >> > >> (IO::Path) method lines > >> Defined as: > >> > >> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = > >> ["\x0A", "\r\n"], |c --> Seq:D) > >> > >> Opens the invocant and returns its lines. > >> > >> The behavior is equivalent to opening the file specified > >> by the invocant, forwarding the :$chomp, :$enc, and > >> :$nl-in arguments to IO::Handle.open, then calling > >> IO::Handle.lines on that handle, forwarding any of > >> the remaining arguments to that method, and returning > >> the resultant Seq. > >> > >> The "signature" line (cryptogram) clearly stated that > >> ":$chomp" is a parameter of the method. > >> > >> Now you are obviously correct that :chomp is ignored. > >> If I am not mistaken, I have just tripped over another > >> error in the documentation. Your take? > >> > > > > You confuse two methods that have the same name "lines". One of them, > > which exists in the IO::Path class, has a :chomp argument. The other, > > on IO::Handle does not. > > > > "path".IO.lines() <-- calls lines on an IO::Path (supports > :chomp) > > "path".IO.open.lines() <-- calls lines on an IO::Handle (does not > support :chomp) > > > > In the second case, if you want chomping to happen you have to pass > > the :chomp to the *open* call, as you do below: > > Hi Tobias, > > The terrible example they included was: > '50GB-file'.IO.lines.grep(*.contains: 'Perl').elems, > " lines that mention Perl"; > > I left off the "grep" and the "elems". > > "Lines.txt".IO.open.lines > > This was the example they gave for > > method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = > ["\x0A", "\r\n"], |c --> Seq:D) > > Exactly what is "IO::Path:D:"? > > I know that :D is declared and the ":" after it > is a delimiter. That leaved "IO::Path": > > https://docs.raku.org/type/IO::Path > > And I can't make heads or tails out of the page. > > My goal is to learn how to use :$chomp = True, > :$enc = 'utf8', :$nl-in, and, |c > > Thank you for the help! > -T >