slurp so many?

Hi All,

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?

Many thanks,
-T
0
perl6
10/7/2018 11:41:48 PM
perl.perl6.users 1111 articles. 0 followers. Follow

11 Replies
51 Views

Similar Articles

[PageSpeed] 7

--0000000000009edf130577ac33db
Content-Type: text/plain; charset="UTF-8"

The whole point of slurp is (possibly lazily in the future) reading
everything. If you want to read by bytes, it's the read method; by lines,
it's get; for extended characters / graphemes, it's readchars. They all
have rather different intents.

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

> Hi All,
>
> 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?
>
> Many thanks,
> -T
>


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

--0000000000009edf130577ac33db
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">The whole point of slurp is (possibly lazily in the future=
) reading everything. If you want to read by bytes, it&#39;s the read metho=
d; by lines, it&#39;s get; for extended characters / graphemes, it&#39;s re=
adchars. They all have rather different intents.</div><br><div class=3D"gma=
il_quote"><div dir=3D"ltr">On Sun, Oct 7, 2018 at 7:42 PM ToddAndMargo via =
perl6-users &lt;<a href=3D"mailto:perl6-users@perl.org">perl6-users@perl.or=
g</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin=
:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi All,<br>
<br>
I use `slurp` all the time, so of course, I can&#39;t<br>
make heads or tails out of<br>
<br>
=C2=A0 =C2=A0 =C2=A0 <a href=3D"https://docs.perl6.org/routine/slurp" rel=
=3D"noreferrer" target=3D"_blank">https://docs.perl6.org/routine/slurp</a><=
br>
<br>
I want to slurp the first 400 characters of<br>
a file and close the handle.=C2=A0 Am I missing a<br>
`so many` parameter somewhere?<br>
<br>
Many thanks,<br>
-T<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"l=
tr"><div><div dir=3D"ltr"><div>brandon s allbery kf8nh</div><div><a href=3D=
"mailto:allbery.b@gmail.com" target=3D"_blank">allbery.b@gmail.com</a></div=
></div></div></div></div>

--0000000000009edf130577ac33db--
0
allbery
10/7/2018 11:52:37 PM
--00000000000048a68a0577ac38b1
Content-Type: text/plain; charset="UTF-8"

On Sun, Oct 7, 2018 at 7:42 PM ToddAndMargo via perl6-users <
perl6-users@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

--00000000000048a68a0577ac38b1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><br><br><div class=3D"gm=
ail_quote"><div dir=3D"ltr">On Sun, Oct 7, 2018 at 7:42 PM ToddAndMargo via=
 perl6-users &lt;<a href=3D"mailto:perl6-users@perl.org">perl6-users@perl.o=
rg</a>&gt; wrote:</div><blockquote class=3D"gmail_quote" style=3D"margin:0p=
x 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I use `slurp` all the time, so of course, I can&#39;t<br>
make heads or tails out of<br>
<br>
=C2=A0 =C2=A0 =C2=A0 <a href=3D"https://docs.perl6.org/routine/slurp" rel=
=3D"noreferrer" target=3D"_blank">https://docs.perl6.org/routine/slurp</a><=
br>
<br>
I want to slurp the first 400 characters of<br>
a file and close the handle.=C2=A0 Am I missing a<br>
`so many` parameter somewhere?<br></blockquote><div><br></div><div>The purp=
ose of slurp is to read the whole file -- if you want part of it, look for =
..words(), .lines(), .read(),</div><div>and for the specific use you point o=
ut, .readchars() --=C2=A0=C2=A0</div><div><a href=3D"https://docs.perl6.org=
/type/IO::Handle#method_readchars">https://docs.perl6.org/type/IO::Handle#m=
ethod_readchars</a><br></div><div><br></div><div>Something like this:</div>=
<div><br></div><div>my $io =3D &quot;myfile&quot;.IO.open;</div><div>my $st=
art =3D $io.readchars(400);</div><div>$io.close;</div><div><br></div><div>C=
urt</div><div><br></div></div></div></div></div>

--00000000000048a68a0577ac38b1--
0
curt
10/7/2018 11:53:53 PM
I think the easiest way to get a 400 characters from a file is with
..comb() on the file.

   'example.txt'.IO.comb(400).head()
On Sun, Oct 7, 2018 at 6:42 PM ToddAndMargo via perl6-users
<perl6-users@perl.org> wrote:
>
> Hi All,
>
> 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?
>
> Many thanks,
> -T
0
b2gills
10/8/2018 12:47:18 AM
On 10/7/18 5:47 PM, Brad Gilbert wrote:
> I think the easiest way to get a 400 characters from a file is with
> .comb() on the file.
> 
>     'example.txt'.IO.comb(400).head()
> On Sun, Oct 7, 2018 at 6:42 PM ToddAndMargo via perl6-users
> <perl6-users@perl.org> wrote:
>>
>> Hi All,
>>
>> 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?
>>
>> Many thanks,
>> -T

Hi Brad,

The files I will be examining are upwards to 250 MB.
So I really only want the first 400 bytes.

I read
      https://docs.perl6.org/routine/comb
and could ot make heads or tails out of it.  But
don't try to explain it to me -- that is a job for
another day.

Thank you!
-T
0
perl6
10/8/2018 2:22:41 AM
On 10/7/18 4:53 PM, Curt Tilmes wrote:
>=20
>=20
> On Sun, Oct 7, 2018 at 7:42 PM ToddAndMargo via perl6-users=20
> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>=20
>     I use `slurp` all the time, so of course, I can't
>     make heads or tails out of
>=20
>     https://docs.perl6.org/routine/slurp
>=20
>     I want to slurp the first 400 characters of
>     a file and close the handle.=C2=A0 Am I missing a
>     `so many` parameter somewhere?
>=20
>=20
> The purpose of slurp is to read the whole file -- if you want part of=20
> it, look for .words(), .lines(), .read(),
> and for the specific use you point out, .readchars() --
> https://docs.perl6.org/type/IO::Handle#method_readchars
>=20
> Something like this:
>=20
> my $io =3D "myfile".IO.open;
> my $start =3D $io.readchars(400);
> $io.close;
>=20
> Curt
>=20


Hi Curt,

Thank you!  Readchars it is!  I will make a sub call out of it.

Where is my typo?

$ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my Str $f=3Dreadchars( $fh,=
=20
400 ); say so $f.constains( chr(0) );'

=3D=3D=3DSORRY!=3D=3D=3D 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.



--=20
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
10/8/2018 2:54:14 AM
On 10/7/18 4:52 PM, Brandon Allbery wrote:
> The whole point of slurp is (possibly lazily in the future) reading 
> everything. 

I was just hoping for 1002 ways of doing tings.


> If you want to read by bytes, it's the read method; by 
> lines, it's get; for extended characters / graphemes, it's readchars. 
> They all have rather different intents.

readchars it is!

Thank you!

-T
0
perl6
10/8/2018 2:55:08 AM
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=20
>> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>>
>> =C2=A0=C2=A0=C2=A0 I use `slurp` all the time, so of course, I can't
>> =C2=A0=C2=A0=C2=A0 make heads or tails out of
>>
>> =C2=A0=C2=A0=C2=A0 https://docs.perl6.org/routine/slurp
>>
>> =C2=A0=C2=A0=C2=A0 I want to slurp the first 400 characters of
>> =C2=A0=C2=A0=C2=A0 a file and close the handle.=C2=A0 Am I missing a
>> =C2=A0=C2=A0=C2=A0 `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 =3D "myfile".IO.open;
>> my $start =3D $io.readchars(400);
>> $io.close;
>>
>> Curt
>>
>=20
>=20
> Hi Curt,
>=20
> Thank you!=C2=A0 Readchars it is!=C2=A0 I will make a sub call out of i=
t.
>=20
> Where is my typo?
>=20
> $ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my Str $f=3Dreadchars( $f=
h,=20
> 400 ); say so $f.constains( chr(0) );'
>=20
> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
> Undeclared routine:
>  =C2=A0=C2=A0=C2=A0 readchars used at line 1
>=20
> $ perl6 -v
> This is Rakudo version 2018.06 built on MoarVM version 2018.06
> implementing Perl 6.c.
>=20
>=20
>=20


Oopos!  It is a method.

$ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my Str $f =3D $fh.readchars=
(=20
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


--=20
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
10/8/2018 2:58:59 AM
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=20
>>> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>>>
>>> =C2=A0=C2=A0=C2=A0 I use `slurp` all the time, so of course, I can't
>>> =C2=A0=C2=A0=C2=A0 make heads or tails out of
>>>
>>> =C2=A0=C2=A0=C2=A0 https://docs.perl6.org/routine/slurp
>>>
>>> =C2=A0=C2=A0=C2=A0 I want to slurp the first 400 characters of
>>> =C2=A0=C2=A0=C2=A0 a file and close the handle.=C2=A0 Am I missing a
>>> =C2=A0=C2=A0=C2=A0 `so many` parameter somewhere?
>>>
>>>
>>> The purpose of slurp is to read the whole file -- if you want part of=
=20
>>> 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 =3D "myfile".IO.open;
>>> my $start =3D $io.readchars(400);
>>> $io.close;
>>>
>>> Curt
>>>
>>
>>
>> Hi Curt,
>>
>> Thank you!=C2=A0 Readchars it is!=C2=A0 I will make a sub call out of =
it.
>>
>> Where is my typo?
>>
>> $ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my Str $f=3Dreadchars( $=
fh,=20
>> 400 ); say so $f.constains( chr(0) );'
>>
>> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
>> Undeclared routine:
>> =C2=A0=C2=A0=C2=A0=C2=A0 readchars used at line 1
>>
>> $ perl6 -v
>> This is Rakudo version 2018.06 built on MoarVM version 2018.06
>> implementing Perl 6.c.
>>
>>
>>
>=20
>=20
> Oopos!=C2=A0 It is a method.
>=20
> $ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my Str $f =3D $fh.readcha=
rs(=20
> 400 ); $fh.close; say so $f.constains( chr(0) );'
>=20
> Malformed UTF-8
>  =C2=A0 in block <unit> at -e line 1
>=20
> What is with the Malformed UTF-8?=C2=A0 Is readchars not binary?
>=20
> -T
>=20
>=20


With a text file and with a binary file and contains speeled
right.


$ p6 'my $fh=3Dopen "/home/linuxutil/X11Test.pl6", :r; my Str $f =3D=20
$fh.readchars( 400 ); $fh.close; say so $f.contains( chr(0) );'

False


$ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my Str $f =3D $fh.readchars=
(=20
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?
0
perl6
10/8/2018 3:02:49 AM
--00000000000092fb6c0577aefadc
Content-Type: text/plain; charset="UTF-8"

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-users@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-users@perl.org <mailto:perl6-users@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
allbery.b@gmail.com

--00000000000092fb6c0577aefadc
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Use the read method instead. I did say in my previous mess=
age that .read is for bytes, .readchars is for graphemes (UTF8 characters p=
lus any modifiers).</div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On=
 Sun, Oct 7, 2018 at 11:03 PM ToddAndMargo via perl6-users &lt;<a href=3D"m=
ailto:perl6-users@perl.org">perl6-users@perl.org</a>&gt; wrote:<br></div><b=
lockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px =
#ccc solid;padding-left:1ex">On 10/7/18 7:58 PM, ToddAndMargo via perl6-use=
rs wrote:<br>
&gt; On 10/7/18 7:54 PM, ToddAndMargo via perl6-users wrote:<br>
&gt;&gt; On 10/7/18 4:53 PM, Curt Tilmes wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Sun, Oct 7, 2018 at 7:42 PM ToddAndMargo via perl6-users <b=
r>
&gt;&gt;&gt; &lt;<a href=3D"mailto:perl6-users@perl.org" target=3D"_blank">=
perl6-users@perl.org</a> &lt;mailto:<a href=3D"mailto:perl6-users@perl.org"=
 target=3D"_blank">perl6-users@perl.org</a>&gt;&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0 I use `slurp` all the time, so of course, I=
 can&#39;t<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0 make heads or tails out of<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0 <a href=3D"https://docs.perl6.org/routine/s=
lurp" rel=3D"noreferrer" target=3D"_blank">https://docs.perl6.org/routine/s=
lurp</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0 I want to slurp the first 400 characters of=
<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0 a file and close the handle.=C2=A0 Am I mis=
sing a<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0 `so many` parameter somewhere?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; The purpose of slurp is to read the whole file -- if you want =
part of <br>
&gt;&gt;&gt; it, look for .words(), .lines(), .read(),<br>
&gt;&gt;&gt; and for the specific use you point out, .readchars() --<br>
&gt;&gt;&gt; <a href=3D"https://docs.perl6.org/type/IO::Handle#method_readc=
hars" rel=3D"noreferrer" target=3D"_blank">https://docs.perl6.org/type/IO::=
Handle#method_readchars</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Something like this:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; my $io =3D &quot;myfile&quot;.IO.open;<br>
&gt;&gt;&gt; my $start =3D $io.readchars(400);<br>
&gt;&gt;&gt; $io.close;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Curt<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Hi Curt,<br>
&gt;&gt;<br>
&gt;&gt; Thank you!=C2=A0 Readchars it is!=C2=A0 I will make a sub call out=
 of it.<br>
&gt;&gt;<br>
&gt;&gt; Where is my typo?<br>
&gt;&gt;<br>
&gt;&gt; $ p6 &#39;my $fh=3Dopen &quot;/home/linuxutil/To&quot;, :r; my Str=
 $f=3Dreadchars( $fh, <br>
&gt;&gt; 400 ); say so $f.constains( chr(0) );&#39;<br>
&gt;&gt;<br>
&gt;&gt; =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e<br>
&gt;&gt; Undeclared routine:<br>
&gt;&gt; =C2=A0=C2=A0=C2=A0=C2=A0 readchars used at line 1<br>
&gt;&gt;<br>
&gt;&gt; $ perl6 -v<br>
&gt;&gt; This is Rakudo version 2018.06 built on MoarVM version 2018.06<br>
&gt;&gt; implementing Perl 6.c.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt; <br>
&gt; <br>
&gt; Oopos!=C2=A0 It is a method.<br>
&gt; <br>
&gt; $ p6 &#39;my $fh=3Dopen &quot;/home/linuxutil/To&quot;, :r; my Str $f =
=3D $fh.readchars( <br>
&gt; 400 ); $fh.close; say so $f.constains( chr(0) );&#39;<br>
&gt; <br>
&gt; Malformed UTF-8<br>
&gt;=C2=A0 =C2=A0 in block &lt;unit&gt; at -e line 1<br>
&gt; <br>
&gt; What is with the Malformed UTF-8?=C2=A0 Is readchars not binary?<br>
&gt; <br>
&gt; -T<br>
&gt; <br>
&gt; <br>
<br>
<br>
With a text file and with a binary file and contains speeled<br>
right.<br>
<br>
<br>
$ p6 &#39;my $fh=3Dopen &quot;/home/linuxutil/X11Test.pl6&quot;, :r; my Str=
 $f =3D <br>
$fh.readchars( 400 ); $fh.close; say so $f.contains( chr(0) );&#39;<br>
<br>
False<br>
<br>
<br>
$ p6 &#39;my $fh=3Dopen &quot;/home/linuxutil/To&quot;, :r; my Str $f =3D $=
fh.readchars( <br>
400 ); $fh.close; say so $f.contains( chr(0) );&#39;<br>
<br>
Malformed UTF-8<br>
=C2=A0 =C2=A0in block &lt;unit&gt; at -e line 1<br>
<br>
how do I rid myself oof the UTF-8 error?<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"l=
tr"><div><div dir=3D"ltr"><div>brandon s allbery kf8nh</div><div><a href=3D=
"mailto:allbery.b@gmail.com" target=3D"_blank">allbery.b@gmail.com</a></div=
></div></div></div></div>

--00000000000092fb6c0577aefadc--
0
allbery
10/8/2018 3:11:24 AM
On 10/7/18 8:11 PM, Brandon Allbery wrote:
> Use the read method instead. I did say in my previous message that .rea=
d=20
> is for bytes, .readchars is for graphemes (UTF8 characters plus any=20
> modifiers).
>=20
> On Sun, Oct 7, 2018 at 11:03 PM ToddAndMargo via perl6-users=20
> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>=20
>     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-users@perl.org <mailto:perl6-users@perl.org>
>     <mailto:perl6-users@perl.org <mailto:perl6-users@perl.org>>> wrote:=

>      >>>
>      >>> =C2=A0=C2=A0=C2=A0 I use `slurp` all the time, so of course, I=
 can't
>      >>> =C2=A0=C2=A0=C2=A0 make heads or tails out of
>      >>>
>      >>> https://docs.perl6.org/routine/slurp
>      >>>
>      >>> =C2=A0=C2=A0=C2=A0 I want to slurp the first 400 characters of=

>      >>> =C2=A0=C2=A0=C2=A0 a file and close the handle.=C2=A0 Am I mis=
sing a
>      >>> =C2=A0=C2=A0=C2=A0 `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 =3D "myfile".IO.open;
>      >>> my $start =3D $io.readchars(400);
>      >>> $io.close;
>      >>>
>      >>> Curt
>      >>>
>      >>
>      >>
>      >> Hi Curt,
>      >>
>      >> Thank you!=C2=A0 Readchars it is!=C2=A0 I will make a sub call =
out of it.
>      >>
>      >> Where is my typo?
>      >>
>      >> $ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my Str $f=3Dreadc=
hars(
>     $fh,
>      >> 400 ); say so $f.constains( chr(0) );'
>      >>
>      >> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
>      >> Undeclared routine:
>      >> =C2=A0=C2=A0=C2=A0=C2=A0 readchars used at line 1
>      >>
>      >> $ perl6 -v
>      >> This is Rakudo version 2018.06 built on MoarVM version 2018.06
>      >> implementing Perl 6.c.
>      >>
>      >>
>      >>
>      >
>      >
>      > Oopos!=C2=A0 It is a method.
>      >
>      > $ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my Str $f =3D
>     $fh.readchars(
>      > 400 ); $fh.close; say so $f.constains( chr(0) );'
>      >
>      > Malformed UTF-8
>      >=C2=A0 =C2=A0 in block <unit> at -e line 1
>      >
>      > What is with the Malformed UTF-8?=C2=A0 Is readchars not binary?=

>      >
>      > -T
>      >
>      >
>=20
>=20
>     With a text file and with a binary file and contains speeled
>     right.
>=20
>=20
>     $ p6 'my $fh=3Dopen "/home/linuxutil/X11Test.pl6", :r; my Str $f =3D=

>     $fh.readchars( 400 ); $fh.close; say so $f.contains( chr(0) );'
>=20
>     False
>=20
>=20
>     $ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my Str $f =3D $fh.rea=
dchars(
>     400 ); $fh.close; say so $f.contains( chr(0) );'
>=20
>     Malformed UTF-8
>      =C2=A0 =C2=A0in block <unit> at -e line 1
>=20
>     how do I rid myself oof the UTF-8 error?
>=20
>=20
>=20
> --=20
> brandon s allbery kf8nh
> allbery.b@gmail.com <mailto:allbery.b@gmail.com>


$ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my Str $f =3D $fh.read( 400=
 );=20
$fh.close; say so $f.contains( chr(0) );'

Type check failed in assignment to $f; expected Str but got Buf[uint8]=20
(Buf[uint8].new(87,111,114,100,8...)
   in block <unit> at -e line 1

:'(
0
perl6
10/8/2018 3:13:42 AM
On 10/7/18 8:13 PM, ToddAndMargo via perl6-users wrote:
> On 10/7/18 8:11 PM, Brandon Allbery wrote:
>> Use the read method instead. I did say in my previous message that=20
>> .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=20
>> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>>
>> =C2=A0=C2=A0=C2=A0 On 10/7/18 7:58 PM, ToddAndMargo via perl6-users wr=
ote:
>> =C2=A0=C2=A0=C2=A0=C2=A0 > On 10/7/18 7:54 PM, ToddAndMargo via perl6-=
users wrote:
>> =C2=A0=C2=A0=C2=A0=C2=A0 >> On 10/7/18 4:53 PM, Curt Tilmes wrote:
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> On Sun, Oct 7, 2018 at 7:42 PM ToddAndMar=
go via perl6-users
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> <perl6-users@perl.org <mailto:perl6-users=
@perl.org>
>> =C2=A0=C2=A0=C2=A0 <mailto:perl6-users@perl.org <mailto:perl6-users@pe=
rl.org>>> wrote:
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> =C2=A0=C2=A0=C2=A0 I use `slurp` all the =
time, so of course, I can't
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> =C2=A0=C2=A0=C2=A0 make heads or tails ou=
t of
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> https://docs.perl6.org/routine/slurp
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> =C2=A0=C2=A0=C2=A0 I want to slurp the fi=
rst 400 characters of
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> =C2=A0=C2=A0=C2=A0 a file and close the h=
andle.=C2=A0 Am I missing a
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> =C2=A0=C2=A0=C2=A0 `so many` parameter so=
mewhere?
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> The purpose of slurp is to read the whole=
 file -- if you want
>> =C2=A0=C2=A0=C2=A0 part of
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> it, look for .words(), .lines(), .read(),=

>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> and for the specific use you point out, .=
readchars() --
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> https://docs.perl6.org/type/IO::Handle#me=
thod_readchars
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> Something like this:
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> my $io =3D "myfile".IO.open;
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> my $start =3D $io.readchars(400);
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> $io.close;
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>> Curt
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >> Hi Curt,
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >> Thank you!=C2=A0 Readchars it is!=C2=A0 I =
will make a sub call out of it.
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >> Where is my typo?
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >> $ p6 'my $fh=3Dopen "/home/linuxutil/To", =
:r; my Str $f=3Dreadchars(
>> =C2=A0=C2=A0=C2=A0 $fh,
>> =C2=A0=C2=A0=C2=A0=C2=A0 >> 400 ); say so $f.constains( chr(0) );'
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >> =3D=3D=3DSORRY!=3D=3D=3D Error while compi=
ling -e
>> =C2=A0=C2=A0=C2=A0=C2=A0 >> Undeclared routine:
>> =C2=A0=C2=A0=C2=A0=C2=A0 >> =C2=A0=C2=A0=C2=A0=C2=A0 readchars used at=
 line 1
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >> $ perl6 -v
>> =C2=A0=C2=A0=C2=A0=C2=A0 >> This is Rakudo version 2018.06 built on Mo=
arVM version 2018.06
>> =C2=A0=C2=A0=C2=A0=C2=A0 >> implementing Perl 6.c.
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >>
>> =C2=A0=C2=A0=C2=A0=C2=A0 >
>> =C2=A0=C2=A0=C2=A0=C2=A0 >
>> =C2=A0=C2=A0=C2=A0=C2=A0 > Oopos!=C2=A0 It is a method.
>> =C2=A0=C2=A0=C2=A0=C2=A0 >
>> =C2=A0=C2=A0=C2=A0=C2=A0 > $ p6 'my $fh=3Dopen "/home/linuxutil/To", :=
r; my Str $f =3D
>> =C2=A0=C2=A0=C2=A0 $fh.readchars(
>> =C2=A0=C2=A0=C2=A0=C2=A0 > 400 ); $fh.close; say so $f.constains( chr(=
0) );'
>> =C2=A0=C2=A0=C2=A0=C2=A0 >
>> =C2=A0=C2=A0=C2=A0=C2=A0 > Malformed UTF-8
>> =C2=A0=C2=A0=C2=A0=C2=A0 >=C2=A0 =C2=A0 in block <unit> at -e line 1
>> =C2=A0=C2=A0=C2=A0=C2=A0 >
>> =C2=A0=C2=A0=C2=A0=C2=A0 > What is with the Malformed UTF-8?=C2=A0 Is =
readchars not binary?
>> =C2=A0=C2=A0=C2=A0=C2=A0 >
>> =C2=A0=C2=A0=C2=A0=C2=A0 > -T
>> =C2=A0=C2=A0=C2=A0=C2=A0 >
>> =C2=A0=C2=A0=C2=A0=C2=A0 >
>>
>>
>> =C2=A0=C2=A0=C2=A0 With a text file and with a binary file and contain=
s speeled
>> =C2=A0=C2=A0=C2=A0 right.
>>
>>
>> =C2=A0=C2=A0=C2=A0 $ p6 'my $fh=3Dopen "/home/linuxutil/X11Test.pl6", =
:r; my Str $f =3D
>> =C2=A0=C2=A0=C2=A0 $fh.readchars( 400 ); $fh.close; say so $f.contains=
( chr(0) );'
>>
>> =C2=A0=C2=A0=C2=A0 False
>>
>>
>> =C2=A0=C2=A0=C2=A0 $ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my St=
r $f =3D=20
>> $fh.readchars(
>> =C2=A0=C2=A0=C2=A0 400 ); $fh.close; say so $f.contains( chr(0) );'
>>
>> =C2=A0=C2=A0=C2=A0 Malformed UTF-8
>> =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0in block <unit> at -e line 1
>>
>> =C2=A0=C2=A0=C2=A0 how do I rid myself oof the UTF-8 error?
>>
>>
>>
>> --=20
>> brandon s allbery kf8nh
>> allbery.b@gmail.com <mailto:allbery.b@gmail.com>
>=20
>=20
> $ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my Str $f =3D $fh.read( 4=
00 );=20
> $fh.close; say so $f.contains( chr(0) );'
>=20
> Type check failed in assignment to $f; expected Str but got Buf[uint8] =

> (Buf[uint8].new(87,111,114,100,8...)
>  =C2=A0 in block <unit> at -e line 1
>=20
> :'(

I just found out I can't use `contains` with a type Buf.  Is
there a contains for Buf?

$ p6 'my $fh=3Dopen "/home/linuxutil/To", :r; my Buf $f =3D $fh.read( 400=
 );=20
$fh.close; my $g=3D$f.Str; say so $g.contains( chr(0) );'

Cannot use a Buf as a string, but you called the Str method on it
   in block <unit> at -e line 1
0
perl6
10/8/2018 3:18:05 AM
Reply: