develooper Front page | perl.perl6.users | Postings from October 2018

Re: eof ?

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
October 9, 2018 12:44
Subject:
Re: eof ?
Message ID:
fd9d32a5-43cc-ca75-302f-df3b3a81a20e@zoho.com
On 10/9/18 5:03 AM, ToddAndMargo via perl6-users wrote:
>>> Le mar. 9 oct. 2018 à 10:03, ToddAndMargo via perl6-users 
>>> <perl6-users@perl.org <mailto:perl6-users@perl.org>> a écrit :
>>>
>>>     Hi All,
>>>
>>>     When reading a text file
>>>     https://docs.perl6.org/routine/lines
>>>     seems pretty straight forward.
>>>
>>>     Question:  How do I tell when I when I have
>>>     reached the EOF (End Of File)?
>>>
>>>     Many thanks,
>>>     -T
>>>
> 
> On 10/9/18 4:38 AM, Laurent Rosenfeld via perl6-users wrote:
>> The eof method of the IO::Handle class returns True if you exhausted 
>> the contents of the handle, but you generally don't need to use that, 
>> since something like:
>>
>> for'input.txt'.IO.lines->$line{
>> # Do something with $line
>> }
>>
>> will gracefully handle ends of files for you without you having to do 
>> anything special.
> 
> Hi Laurent,
> 
> Thank you!
> 
> So loop until lines return false?
> 
> Is it just me, or is this not documented on
> 
>       https://docs.perl6.org/routine/lines
> ?
> 
> -T


Where in the following would I put a echo of the True / False
return from `lines`?

$ p6 'my $fh=open "/home/linuxutil/WhoIsMySub.pl6", :r;  for $fh.lines { 
say $_}; $fh.close;'

Thread Previous | Thread Next


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