On Mon, Oct 8, 2018 at 7:06 AM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> $ p6 'my $fh=open "/home/linuxutil/To", :r; my Buf $f = $fh.read( 10 );
> $fh.close; dd $f; for $f[0..*] -> $Byte { if $Byte == 0b00 {say
> "Binary"; last;}else{say $Byte}}'
>
> Buf[uint8] $f = Buf[uint8].new(87,111,114,100,80,114,111,0,0,0)
>
> 87
> 111
> 114
> 100
> 80
> 114
> 111
> Binary
>
> To get the above to work, I had to say `$f[0..*]`. If I used
> `$f`, it made one loop over the entire variable.
>
> $ p6 'my $fh=open "/home/linuxutil/To", :r; my Buf $f = $fh.read( 10 );
> $fh.close; dd $f; for $f -> $Byte { if $Byte == 0b00 {say "Binary";
> last;}else{say $Byte}}'
>
> Buf[uint8] $f = Buf[uint8].new(87,111,114,100,80,114,111,0,0,0)
> Buf[uint8]:0x<57 6f 72 64 50 72 6f 00 00 00>
>
>
> I never have to say `$str[0..*]` when looping over a string.  Why?
>

How do you loop over a string?  Doesn't 'for $str' just also run the loop
once?

Your $f is one thing (it is a scalar), so for $f will just do one thing.
You can also use for $f.list or for @$f

Curt

Reply via email to