I have a smallish perl script that parses/generates binary streams (a select subset of OpenPGP/RFC 4880 packets). It needs to run cleanly in both perl 5.8 and 5.10 environments for portability, and i've run into some confusion about the changes in pack and unpack between perl 5.8 and 5.10. In particular, i occasionally need to pack and unpack raw 8-bit values, (and to checksum them) and the unicode transitions have left me confused.
I've explicitly set use bytes;, but i'm not convinced that this is enough to ensure that i don't get screwed up results when run under unexpected locales or environments. I'm looking for guidance.
perldoc -f unpack references SYSV checksums in both versions, but 5.8 shows the algorithm as:
while 5.10 shows it as:$checksum = do { local $/; # slurp! unpack("%32C*",<>) % 65535; };
Is there a way to compute this portably without explicitly checking the version number of perl that is running? Can someone give me a concrete example of how it might break in 5.10 if i use "%32C*" instead of %32W*?$checksum = do { local $/; # slurp! unpack("%32W*",<>) % 65535; };
In a related note, when i'm un/packing literal bytes (but not checksumming), I'm currently using "C" -- should i be using something else? Do i need to be explicitly doing something to the incoming/outgoing data to force it to be treated as a binary blob instead of as a unicode string, even though i'm already declaring use bytes;?
In my research for this, i came across a post that leaves me worried about unexpected behavior from the rest of the archive, but i confess i don't understand the issues well enough to understand that post well enough to know what the Right Thing to do is for code that needs to be able to run correctly under both 5.8 and 5.10 and deals with raw binary data.
Any advice or pointers to specific reading would be most appreciated.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |