On 10/9/18 5:42 AM, Fernando Santagata wrote:
The answer Laurent Roseenfeld gave you works for read and readchars as well.
Save the following lines in a file and run it (try and change .read into .readchars too); it will output a series of 10-byte long Buf[uint8]s, until it reaches the end of file.

#!/usr/bin/env perl6
given $*PROGRAM-NAME.IO.open {
   while my $bytes = .read: 10 {
     $bytes.say;
   }
}

On Tue, Oct 9, 2018 at 10:17 AM ToddAndMargo via perl6-users <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:

    On 10/9/18 1:02 AM, ToddAndMargo via perl6-users wrote:
     > 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

    Please expand the question to include `read` and `readchars`.



--
Fernando Santagata

Hi Frenando,

Thank you for the help!

I am not getting anywhere with `.lines`. Read the whole thing in the first line.

$ p6 'my $fh=open "/home/linuxutil/WhoIsMySub.pl6", :r; while my $f = $fh.lines { say "$f\n"}; $fh.close;'

#!/usr/bin/env perl6 sub f() { put &?ROUTINE.gist; }; sub abc () { say "This subroutine's ID is ", f; print "\n"; &?ROUTINE.gist ~~ m/' '(.*?)' '\(/; my $SubName = $0; say "This subroutine is called $SubName"; } abc;

-T

Reply via email to