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

Re: binary test and position?

Thread Previous | Thread Next
From:
Brad Gilbert
Date:
February 2, 2019 03:36
Subject:
Re: binary test and position?
Message ID:
CAD2L-T0iS=ZE+uhk7L3bCATMAS6r2-nWQitc8qwAqO7S+QYBHg@mail.gmail.com
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'))

On Fri, Feb 1, 2019 at 9:22 PM ToddAndMargo via perl6-users
<perl6-users@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

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