[Chicago-talk] Parsing a Hex file

Jay Strauss me at heyjay.com
Fri Jan 19 14:21:15 PST 2007

> However, I'm pretty sure the following loop will do what you're looking for:
>     while (length($file_contents)) {
>         my ($field_num, $value) = unpack("SC/A", $file_contents);
>         # something with $field_num and $value
>         my $len = length($value);
>         $file_contents = substr($file_contents,$len+3);
>     }
> Of course, I'm using "C" to mean "8-bit integer", but I don't know any
> more elegant way to do that.
> -Pete K

Thanks Pete, that's almost working.  It parses the correct number of
bytes but the values for the field_num are wrong.  I can't tell if its
a signed/unsigned issue, or a big/little endian thing.

For example its taking (hex):
94 00 0B 4A 41 59 27 53 20 46 4F 4F 44 53

which should convert into

148 11 JAY'S FOODS

But instead I'm getting:

131 11 JAY'S FOODS

It seems like it should be a un/signed thing but I've tried SC/A and
sC/A, and there's no difference.


More information about the Chicago-talk mailing list