develooper Front page | perl.perl6.users | Postings from September 2020

Re: liens and :chomp question

Thread Previous
From:
ToddAndMargo via perl6-users
Date:
September 1, 2020 02:21
Subject:
Re: liens and :chomp question
Message ID:
9dcbeee0-b09c-f475-404f-27b0c3dbe6d6@zoho.com
On 2020-08-30 08:16, yary wrote:
> 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

Thank you!

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About