in reply to Looking for a hexadecimal byte string in a scalar variable

No need to use an array slice. You can do something like this:

if ($chunk =~ /^\xff\xff\x08\x00/) { print "Chunk in use\n"; } else { print "Chunk not used\n"; }

There's an example of doing similar things with PNG files in chapter 7 of Data Munging with Perl.

update: Fair point. Anchor added.

--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me

Replies are listed 'Best First'.
Re: Re: Looking for a hexadecimal byte string in a scalar variable
by ton (Friar) on Apr 04, 2001 at 22:13 UTC
    You're going to need to use the '^' anchor, e.g.
    if ($chunk =~ /^\xff\xff\x08\x00/) { print "Chunk in use\n"; } else { print "Chunk not used\n"; }
    Otherwise, you'll get a match if that byte sequence is anywhere in the chunk, not just in the beginning.