On 2/2/19 6:09 AM, Brad Gilbert wrote:
sub buf-index ( Buf $buf, +@match ) {
my $elems = @match.elems;
$buf.rotor( $elems => 1 - $elems ).first(* eqv @match.List, :k)
}
my $buf = Buf[uint8].new(0x4D, 0x5A, 0x90, 0x00, 0x03);
say buf-index( $buf, (0x90, 0x00, 0x03)); # 2
What did I do wrong?
First I did a byte wise conversion of
Buf $BinaryFile to Str $StrFile
and
Buf $VersionInfoBuf to Str $VersionInfoStr
sub Buf-Index ( Buf $Buffer, +@SubBuf ) {
# `index` for buffers
# $Buffer is the buffer to search through
# $ +@SubBuf is the sub buffer pattern to search for in $Buffer
# returns the first instance of a match, Nil if no match
my Int $Position = Nil;
my $Elems = @SubBuf.elems;
$Position = $Buffer.rotor( $Elems => 1 - $Elems ).first( * eqv
@SubBuf.List, :k );
return $Position;
}
$i = index( $StrFile, $VersionInfoStr );
$bi = Buf-Index( $BinaryFile, $VersionInfoBuf );
say "i = <$i> bi = <$bi>";
$ FileVer.pl6
i = <11371> bi = <>
11371 is correct.
What did I do wrong?
Many thanks,
-T