in reply to Re^2: How to unpack numbers with varying sizes?
in thread How to unpack numbers with varying sizes?

unpack doesn't support those sizes directly. You could extract them in parts, then assemble them.

# 3-bytes, network order my ($o1, $o2, $o3) = unpack('CCC', $_); my $n = ($o1 << 16) | ($o2 << 8) | $o3; -or- my ($n1, $n2) = unpack('Cn', $_); my $n = ($n1 << 16) | $n2;

Alternatively, you could add padding.

# 3-bytes, network order my $n = unpack('N', "\x00".$_);