SPUG: pack and unpack
Ben Reser
ben at reser.org
Wed Aug 27 19:27:00 CDT 2003
On Wed, Aug 27, 2003 at 04:03:16PM -0700, Richard Wood wrote:
> Right,
>
> Got the "Z" working on a machine with a newer version
> of perl (doesn't work on was 5.004_04, does work on
> 5.005_03). I only have second edition of Camel. I
> will take a look at third edition tonight.
>
> All of my LONGs are coming out 808464432 and all of my
> SHORTS are coming out 12336. I will figure this out
> sooner or later.
>
> Sorry I can't send a file. They belong to a local
> airplane company and I am not at liberty to transmit
> them.
>
> elsif ($type == 3) { # SHORT
> $decoded_value =unpack "n", $value;
> } elsif ($type == 4) { # LONG
> $decoded_value = unpack "N", $value;
> }
I don't know what I was thinking when I wrote that sample code,
This will work better (I hope):
seek(TIF, $offset, 0) or die "Seek $i: $!\n";
read(TIF, $buffer, 8);
($tag, $type, $count, $value) = unpack "nnN", $buffer;
read(TIF, $buffer, 4);
if ($type == 1) {
$value = unpack "C", $buffer;
} elsif ($type == 2) {
$value = unpack "Z$count", $buffer;
} elsif ($type == 3) {
$value =unpack "n", $buffer;
} elsif ($type == 4) {
$value = unpack "N", $buffer;
...
Can't imagine who that local airplane company might be... :)
--
Ben Reser <ben at reser.org>
http://ben.reser.org
"What upsets me is not that you lied to me, but that from now on I can
no longer believe you." -- Nietzsche
More information about the spug-list
mailing list