Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Whenever i run this script, the number is never correct. Are there any obvious errors here?#!/usr/bin/perl -w use strict; use FileHandle; use warnings; my $data = "../file.bin"; my $buffer; my $string; my $n = 0; my $checksum = 0; my $num = 0; my $str = unpack("B32", pack("N", shift)); my $bits = 4; my $decimal; open FILE, $data or die $!; binmode FILE; while (($n = read FILE, $buffer, 4)) { $decimal = unpack("N", pack("B32", $buffer)); {$checksum = $checksum + $decimal; #$num = $num + $bits; #print "1. $num\n"; print "2. $decimal\n"; #print "3. $n bytes read\n"; print "4. $checksum \n"; } $checksum %= 2**32; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Difficulty producing correct checksum
by spazm (Monk) on Jul 16, 2009 at 16:18 UTC | |
by Anonymous Monk on Jul 16, 2009 at 18:07 UTC | |
by spazm (Monk) on Jul 17, 2009 at 16:15 UTC | |
|
Re: Difficulty producing correct checksum
by jrsimmon (Hermit) on Jul 16, 2009 at 16:01 UTC | |
|
Re: Difficulty producing correct checksum
by Anonymous Monk on Jul 16, 2009 at 16:06 UTC |