Syntactic Confectionery Delight | |
PerlMonks |
Re^9: Determining content-length for an HTTP Postby WizardOfUz (Friar) |
on Nov 26, 2009 at 20:46 UTC ( [id://809653]=note: print w/replies, xml ) | Need Help?? |
Well, maybe it's the language barrier. My point is that it is simply not possible to encode $xmldata without knowing from what / to what. The OP told us nothing about the content of $xmldata or the desired encoding. Therefore, the only (quick) advice I could give him was to make sure that length() treats $xmldata as a series of bytes. And that is exactly what the bytes pragma is for. When the bytes pragma is in effect, length() returns the number of bytes taken by Perl's internal string representation. Which is exactly what we need to know for the Content-Length header (assuming that no PerlIO layer has been specified for the outstream): "A user of Perl does not normally need to know nor care how Perl happens to encode its internal strings, but it becomes relevant when outputting Unicode strings to a stream without a PerlIO layer -- one with the "default" encoding. In such a case, the raw bytes used internally (the native character set or UTF-8, as appropriate for each string) will be used, and a "Wide character" warning will be issued if those strings contain a character beyond 0x00FF." The examples in your previous post were certainly interesting, but missed the point, especially the third one, because the only thing we really need to know for the Content-Length header is how many bytes are going to be sent. See above. Furthermore, it is simply not true that the bytes pragma is as unreliable as you depicted it. It only fails (in this context) if you try really hard. See my examples above. And yes, I'm aware that if my advice had solved the wrong Content-Length problem, the follow-up question would probably have been: "Help! My message content is garbled!". That would have been your opportunity to shine ... Peace.
In Section
Seekers of Perl Wisdom
|
|