>
> On Fri, Feb 1, 2019 at 9:22 PM ToddAndMargo via perl6-users
> <perl6-us...@perl.org> wrote:
>>
>> Hi All,
>>
>> On a type Buf, what do I use to check for the
>> position of a byte pattern?
>>
>>
>> Many thanks,
>> -T
On 2/1/19 7:35 PM, Brad Gilbert wrote:
This would work:
my $b = Buf.new( 0,0,0, 1, 2, 0 );
my $match = Buf.new( 1, 2 );
$b.rotor( $match.elems => 1 - $match.elems ).grep(* eqv $match.List, :k)
If you only need the first one, swap out `grep` for `first`
Another iffy option is to decode it as latin1
$b.decode('latin1').index($match.decode('latin1'))
I am trying to avoid decoding.
match is giving me a fit about not being an Any:
$ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b=
$handle.read(5); say $b; say $b[2..4]; if ( $b.match( 0x90,0x00,0x04 ) )
{say "y";} else {say "n"}; $handle.close;'
Buf[uint8]:0x<4D 5A 90 00 03>
(144 0 3)
Invocant of method 'match' must be a type object of type 'Any', not an
object instance of type 'Buf[uint8]'. Did you forget a 'multi'?
in block <unit> at -e line 1
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~