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

How do I address bytes in a Buf/binary variable?

Thread Next
From:
ToddAndMargo via perl6-users
Date:
October 8, 2018 08:25
Subject:
How do I address bytes in a Buf/binary variable?
Message ID:
b0394812-2382-5e92-5983-e69461c2adfb@zoho.com
Hi All!

Question: I am using `read` to read the first 400 bytes of an unknown 
file (could be a binary file).  The 400 bytes go into a variable
of type "Buf".  This is not a string.

p6 'my $fh=open "/home/linuxutil/To", :r; my Buf $f = $fh.read( 400 ); 
$fh.close;'

Now in $f, I want to look at each byte one at a time for a
bitwise pattern using bitwise AND.

How do I address each byte?

`dd` seems to get me the information I need, but it prints it:

     $ p6 'my $fh=open "/home/linuxutil/To", :r; my Buf $f = $fh.read( 
10 ); $fh.close; dd $f;'

     Buf[uint8] $f = Buf[uint8].new(87,111,114,100,80,114,111,0,0,0)

An array of bytes would be great.

Many thanks,
-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