develooper Front page | perl.perl6.users | Postings from October 2018

loop on a Buf/binary

Thread Next
From:
ToddAndMargo via perl6-users
Date:
October 8, 2018 11:05
Subject:
loop on a Buf/binary
Message ID:
164ff1fc-d8d2-d0df-06ef-ce8b18a53330@zoho.com
$ 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?

Yours in confusion,
-T

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About