in reply to Pack & Unpack

I tried to unpack using:
unpack 'i/A*',$_; however it does not seem to work. One thing I've noticed is that if I try to unpack the message from the server whithout the while loop, I only get the first line back + the gibberish. If I do a while loop as in the code then I get all the message + gibberish. Could the problem lie in the fact that the message has a carriage return? I'm drawing a blank

Replies are listed 'Best First'.
Re: Re: Pack & Unpack
by Thelonius (Priest) on Apr 16, 2003 at 15:49 UTC
    You should use a format like "n/A*" if your strings may have binary characters in them. But, if you do use this format, you cannot use <$socket> because the length may contain a "\n" character (e.g. if your string length is 10). You also shouldn't use <$socket> if your strings can contain arbitrary binary data which can include "\n". If you do use "n/A*", you should use read or sysread to read the data. You use the prepended length to tell when you have a complete message.