if (length($payload)%2) { my $padded = substr $payload, 0, -1; $padded .= "\0"; $padded .= substr $payload, -1; ## above: ok, so the next to the last byte ## is guaranteed to be null since we just ## explicitly set it if (ord(substr $padded, -1) >= 128) { my $end = ord(substr $padded, -2, 1); ## ## above: now we're grabbing the next to the last ## byte, even though we already know it's a null? ## my $endend = ord(substr $padded, -1); $end--; ## now we decrement it, knowing full well it's ## going to be -1? $endend--; ###DEBUG: printf "CMPSAT = %i %i\n", $end, $endend; # if 0 before --, then -1 results in warning to pack below # -1 is in essense \xff or 255 if ($end == -1) { $end = 255 } ## ## above,of course, it's going to == -1, and thus ## at this point, always reset to 255 ## if ($endend == -1) { $endend = 255 } $padded = substr $padded, 0, -2; $padded .= CORE::pack('CC', $end, $endend); } $payload = $padded; }