in reply to Length of unpacked string for "hex" data

I'm far from an expert on pack/unpack myself. In fact, I saw your post as a chance to learn a little myself! I think perhaps you should make the 'C' an 'I' in your templates, and then specify the hex data as 16 bits in length. The following worked for me...at least I got all 8 bytes of the hex back.

$record[0] = pack ("A2IA7", "RT", 7, "testing"); $record[1] = pack ("A2IH16", "CD", 16, "01020304FFDDEC19"); # Prints ASCII fields fine, truncates hex for (my $i=0; $i<2; $i++) { my ($kw) = unpack("A2", $record[$i]); my ($rdata) = unpack("x2I/$kwfmt{$kw}", $record[$i]); print "$kw $rdata\n"; }

Replies are listed 'Best First'.
Re^2: Length of unpacked string for "hex" data
by SirBones (Friar) on Apr 24, 2006 at 19:54 UTC

    Thanks for the suggestion. Of course I've managed to present a bad example. Your suggestion of "I" in the template only works if the hex string is 8 bytes or shorter (from what I can see.) In reality my hex strings may be significantly longer.

    Ken

    "This bounty hunter is my kind of scum: Fearless and inventive." --J.T. Hutt