On Wed, May 1, 2013 at 1:15 PM, Steffen Mueller <smueller@cpan.org> wrote: > On 05/01/2013 07:04 PM, Peter Martini wrote: >> >> On Wed, May 1, 2013 at 12:53 PM, Steffen Mueller >> <mail@steffen-mueller.net> wrote: >>> >>> [side-track] >>> >>> On 05/01/2013 06:44 PM, demerphq wrote: >>>> >>>> >>>> My understanding of pack()s original intention was to allow one to >>>> construct C structures in Perl. As such introduces a change which >>>> basically means one cannot safely put a string into a C structure >>>> without the possibility of the entire structure being corrupted by >>>> doing so doesn't make sense. >>> >>> >>> >>> In all fairness, if you use pack to do that, you'll be writing VERY >>> unportable code due to alignment, padding and friends. But don't listen >>> to >>> me: Have a look at the docs for Convert::Binary::C. Marcus knows a lot >>> better than I do. > > >> For what it's worth, I often use pack/unpack when I'm working with >> network protocols. The endianness and encoding are well defined and >> may differ from the architecture of the system I'm working on. The >> main example I can think of was talking from a SPARC/Solaris or >> Intel/linux host to a Windows service, which meant not only did it it >> have to pay attention to endianness for the encoded length fields, it >> had to convert encoded text data from UTF-16 to UTF-8 as well. > > > That's entirely not the same as C structs. :) Sorry, side-tracked the side-track :-) I've done enough with C/C++ and various levels of optimization that I wouldn't ever try to pack a C struct directly - but I've often used C structs as my documentation for on on-disk / over-the-wire format, which is why I think of the two together. > > This being said, I'm surprised you haven't run into the "passing a scalar > with UTF8bit set to pack("v/a")" issue. Are you running old perls? > > --Steffen I haven't had to use that library for years, and yes it was an older perl - maybe 5.8.4? Certainly none of the clients using that were 5.10 or newer.Thread Previous | Thread Next