sub Squish { my ($what) = @_; if ($what =~ /^\-?[0-9]+$/) { if ($what >= 0) { if ($what <= 255) { return pack ("CC", 0x01, $what); } elsif ($what <= 65535) { return pack ("CS", 0x02, $what); } elsif ($what <= 4294967295) { return pack ("CL", 0x04, $what); } } elsif ($what >= -128 && $what <= 127) { return pack ("Cc", 0x09, $what); } elsif ($what >= -32768 && $what <= 32767) { return pack ("Cs", 0x0A, $what); } elsif ($what >= 2147483648 && $what <= 2147483647) { return pack ("Cl", 0x0B, $what); } } elsif ($what =~ /^\-?[0-9]+(?:\.[0-9]+)?(?:e[\+\-]\d+)?$/) { return pack ("Cd", 0x0C, $what); } elsif (length ($what) < 16) { return pack ("C", 0x0C & (length($what) << 4)).$what; } elsif (length ($what) <= 255) { return pack ("CC", 0x0D, length($what)).$what; } return pack ("CS", 0x0E, length($what)).$what; }