Use the read method instead. I did say in my previous message that .read is
for bytes, .readchars is for graphemes (UTF8 characters plus any modifiers).

On Sun, Oct 7, 2018 at 11:03 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 10/7/18 7:58 PM, ToddAndMargo via perl6-users wrote:
> > On 10/7/18 7:54 PM, ToddAndMargo via perl6-users wrote:
> >> On 10/7/18 4:53 PM, Curt Tilmes wrote:
> >>>
> >>>
> >>> On Sun, Oct 7, 2018 at 7:42 PM ToddAndMargo via perl6-users
> >>> <perl6-us...@perl.org <mailto:perl6-us...@perl.org>> wrote:
> >>>
> >>>     I use `slurp` all the time, so of course, I can't
> >>>     make heads or tails out of
> >>>
> >>>     https://docs.perl6.org/routine/slurp
> >>>
> >>>     I want to slurp the first 400 characters of
> >>>     a file and close the handle.  Am I missing a
> >>>     `so many` parameter somewhere?
> >>>
> >>>
> >>> The purpose of slurp is to read the whole file -- if you want part of
> >>> it, look for .words(), .lines(), .read(),
> >>> and for the specific use you point out, .readchars() --
> >>> https://docs.perl6.org/type/IO::Handle#method_readchars
> >>>
> >>> Something like this:
> >>>
> >>> my $io = "myfile".IO.open;
> >>> my $start = $io.readchars(400);
> >>> $io.close;
> >>>
> >>> Curt
> >>>
> >>
> >>
> >> Hi Curt,
> >>
> >> Thank you!  Readchars it is!  I will make a sub call out of it.
> >>
> >> Where is my typo?
> >>
> >> $ p6 'my $fh=open "/home/linuxutil/To", :r; my Str $f=readchars( $fh,
> >> 400 ); say so $f.constains( chr(0) );'
> >>
> >> ===SORRY!=== Error while compiling -e
> >> Undeclared routine:
> >>      readchars used at line 1
> >>
> >> $ perl6 -v
> >> This is Rakudo version 2018.06 built on MoarVM version 2018.06
> >> implementing Perl 6.c.
> >>
> >>
> >>
> >
> >
> > Oopos!  It is a method.
> >
> > $ p6 'my $fh=open "/home/linuxutil/To", :r; my Str $f = $fh.readchars(
> > 400 ); $fh.close; say so $f.constains( chr(0) );'
> >
> > Malformed UTF-8
> >    in block <unit> at -e line 1
> >
> > What is with the Malformed UTF-8?  Is readchars not binary?
> >
> > -T
> >
> >
>
>
> With a text file and with a binary file and contains speeled
> right.
>
>
> $ p6 'my $fh=open "/home/linuxutil/X11Test.pl6", :r; my Str $f =
> $fh.readchars( 400 ); $fh.close; say so $f.contains( chr(0) );'
>
> False
>
>
> $ p6 'my $fh=open "/home/linuxutil/To", :r; my Str $f = $fh.readchars(
> 400 ); $fh.close; say so $f.contains( chr(0) );'
>
> Malformed UTF-8
>    in block <unit> at -e line 1
>
> how do I rid myself oof the UTF-8 error?
>


-- 
brandon s allbery kf8nh
allber...@gmail.com

Reply via email to