Note that the calculation
4 - (length($str) % 4) will cause four null bytes to be appended to a string that is an exactly even number of
'N' fields long. As this effectively adds a zero to an arithmetic checksum, there should be no effect. However, there may be other, similar situations in which there is a
significant effect! The current
unpack-ing behavior of the
N* field specifier and others of its ilk is to ignore any bytes at the end of a string that do not constitute a complete field. If this is true, it is sufficient to simply append a constant string of three null bytes (in the case of the
N specifier) to the end of
every string. Unfortunately, this behavior does not seem not be explicitly specified in the current documentation.
Also note that you define the calcChecksum32 function with a () prototype for an empty argument list, then invoke the function (with an argument!) with the & sigil, which causes any prototype to be ignored. A good rule is to avoid prototypes unless you understand exactly how they work; most programmers, especially those from a C/C++ background, simply don't.
It is also good practice to avoid using the & sigil when invoking functions, using, e.g., calcChecksum32($string) instead. Among other things, this will allow prototypes, if you ever do use them, to actually have some effect! See perlsub for info on prototypes, subroutine invocation, etc.
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.