Scripting‎ > ‎Perl examples‎ > ‎

how to calculate adler32 in perl

Thank you for visiting this page, this page has been update in another link How to calculate adler32 in Perl
Here is an example to calculate adler32 crc for a string :

#!/usr/bin/perl -w

use Compress::Zlib;        # for adler32()

my $crc;
my $string="https://sites.google.com/site/itmyshare/perl-tips-and-examples/how-to-calculate-adler32-in-perl";
print "Calculating checksum for $string ...\n";
$crc = adler32($string,$crc);
printf("adler32:%s\n",$crc);
exit(0);
Run it
$./crc.pl
Calculating checksum for https://sites.google.com/site/itmyshare/perl-tips-and-examples/how-to-calculate-adler32-in-perl
adler32:3158123414


As for how to calculate adler32 for a file, do it this way.

#!/usr/bin/perl

use Compress::Zlib;

$filename=$ARGV[0];
while(<>) {
       $crc=adler32($_,$crc)
       }
       printf("%x %s\n",$crc,$filename);
exit(0);



try to run it
$./adler32.pl ./adler32.pl
64712c9d ./adler32.pl


I think there could be a way to use module
use Digest::Adler32

It should be pretty much similar with the ways I mentioned for md5, but I haven't got chance to try it yet.

https://sites.google.com/site/itmyshare/home/how-to-calculate-md5-of-a-file-string-in-perl




Comments