A colleague and myself noticed a very peculiar behaviour of $! and $@. We were wondering if someone could shed some light on this strange behavior.
Basically, we have an XML document that we are transmitting from a server to a client. Before we send this document we transmit the length of document in four bytes that are arranged in network byte order. The recieving side reads these
bytes off and and determines the content length, and then reads off that many bytes. As the server code is currently implemented, it calls a function to open a unix domain socket,
if this fails the function returns $@. The return values of the connector function are captured in a couple of variables and eventually end up being concatenated into a return message. The length of this message is then calculated. And the length as outlined above and the message are transmitted back to the client. The problem is that we are getting descrepancies in length. The server says that it's string is 462, but when the client reads off the length it sees 451. One might think, aha there is a bug in the client code, alas one would be wrong. When $@ is taken out of the picture, and everything is the same, the code works as expected. Stabbing in the dark we tried some other permutations. We tried referencing $@ directly this caused no change. We attempted to assign the contents of $@ to another variable, to no avail. We've also tried explicitly stringifying $@, and this didn't work. We also compared what length() returned when given $@ and a string literal which contained the same string as $@. Then we tried returning $!, the server showed the length as 413, the client saw the length as 450, but only read 414 which was the whole message. The next scenario involved referencing $! directly. This last one worked as expected. This has completely baffled us. We've checked to make sure $@ wasn't an object or anything funny. This is completely mind boggling. Anyone have something similiar happen, are we missing something?
Update:
Some more detail:
The server will generate
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.