On 6/22/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
I've got a binary file here that I'm reading byte by byte and I'm trying to compare the raw binary data... but I'm running into problems with bytes without an ASCII representation. For example, if I'm looking for hex value 58 its fine, because I can just read a byte and see if ($byte eq "X") since 58 is X in ASCII. What if I want to search for ff or c6 or something which has no ASCII representation?
Maybe you don't want binary data, but hex data? my $hex = unpack "H*", $data; Or maybe you want bytes? my @bytes = unpack "C*", $data; You could do a substring search: my $location = index $data, "X\xff\xc6"; Or maybe you want regular expressions? if ($data =~ /X\xff\xc6/) { print "hmmm...\n" } Does anything there look useful? But if you've got a kind of binary file that anybody else might have wanted to use Perl to look at more than once in the past decade, there's probably a module on CPAN for you. For example, if you were trying to find the xy dimensions of an image file, that's easy with the right module, with no need to muck about in the bytes from within your own code. http://search.cpan.org Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/