develooper Front page | perl.perl6.users | Postings from February 2019

Re: binary test and position?

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
February 2, 2019 03:50
Subject:
Re: binary test and position?
Message ID:
15b2c276-2766-62ec-d25b-43f77bc54ee4@zoho.com
On 2/1/19 7:37 PM, ToddAndMargo via perl6-users wrote:
> On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote:
>> Hi All,
>>
>> On a type Buf, what do I use to check for the
>> position of a byte pattern?
>>
>>
>> Many thanks,
>> -T
> 
> 
> Basically, what am I doing wrong here?
> 
> $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= 
> $handle.read(5); say $b; say $b[2..4];; if ( $b[2..4] eq 0x90,0x00,0x04 
> ) {say "y";} else {say "n"}; $handle.close;'
> Buf[uint8]:0x<4D 5A 90 00 03>
> (144 0 3)
> y
> 
> 
> I am testing to see if the pattern 0x90 0x00 0x04 exists,
> which is does not.


Okya,  no error now, but the WRONG answer:

$ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= 
$handle.read(5); say $b; if ( $b[2..4] == Buf.new(0x90,0x00,0x04) ) {say 
"y";} else {say "n"}; $handle.close;'

Buf[uint8]:0x<4D 5A 90 00 03>
y




-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thread Previous | 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