Decoding 3-byte integer in Perl
问题 I'm reading a binary file format that starts out with 4 constant check bytes, followed by 3 octets that indicate how long the data portion of the record will be. I can decode this as follows: read($fh, $x, 7) or do { last if eof; die "Can't read: $!"; }; my ($type, $l1, $l2, $l3) = unpack("a4 C3", $x); my $length = $l1 << 16 | $l2 << 8 | $l3; Is there a more direct way to read that 3-byte value, without intermediate variables? Something I'm missing in the pack specifications maybe? I haven't