On 10/8/18 4:25 AM, Curt Tilmes wrote:
On Mon, Oct 8, 2018 at 7:21 AM ToddAndMargo via perl6-users
<perl6-us...@perl.org <mailto:perl6-us...@perl.org>> wrote:
> 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
$ p6 'my $x="a\nb\nc\nd"; for split( "\n", $x ) -> $Line { say $Line };'
a
b
c
d
This is not "looping over a string" -- that is actually looping over
the list returned by split().
You can similarly split the Buf with .list() (or just use @$f).
Curt
@$f Worked. Thank you!
$ 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)
87
111
114
100
80
114
111
Binary