in reply to Pack & Unpack

When you use the 'i/A*' format on pack the 'i/'part is requesting pack to prefix the string with a 4-byte integer denoting the length of the following string. This is the "garbage" you are seeing. To remove this, use the same format on the unpack as you used on the pack.

print pack 'i/A*', "1;SS\015" ♣ 1;SS print unpack 'A*', pack 'i/A*', "1;SS\015" ♣ 1;SS print unpack 'i/A*', pack 'i/A*', "1;SS\015" 1;SS

Or don't include it in the first place if you don't need it?


Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

Replies are listed 'Best First'.
Re: Re: Pack & Unpack
by perlplexer (Hermit) on Apr 16, 2003 at 15:28 UTC
    If you want to avoid "mysterious bit flips", don't use platform-specific notation when sending stuff across the network. In your particular case, "i/A* should be "n/A*". Including "n" is equivalent to calling ntohs() on the number.

    --perlplexer