andyd@pogo.WV.TEK.COM (Andy Davidson) (05/20/91)
Newsgroups: comp.perl
Subject: unpack & checksum
Expires:
References:
Sender:
Reply-To: andyd@pogo.WV.TEK.COM (Andy Davidson)
Followup-To:
Distribution: usa
Organization: Tektronix, Inc., Wilsonville, OR.
Keywords:
I am trying to use the snippet of code in the man page to use the unpack
function to generate a 16-bit checksum, i.e.,
while (<>) {
$checksum += unpack("%16C*",$_);
}
$checksum %= 65536;
printf "%ld\n", $checksum;
I also tried the version shown in the Camel book:
undef $/;
$checksum = unpack("%16C*", <>);
printf "%ld\n", $checksum;
However, these report different results than sum does, either on my 4.3BSD
VAX or a Sun running SunOS 4.1. Why? Is there a difference between what
System V 'sum' reports and what BSD 'sum' reports? Or am I doing something
wrong?
I am currently running version 4.0 patchlevel 3.
andy
--
Andy Davidson 503-685-3033 Manager, Tektronix/GPID QA & Tools
Internet: andyd@pogo.WV.tek.com uucp: ...!tektronix!pogo!andyd
Trust, but verify!