Subject: | Difference between funcitonal and OO invocation methods |
The two scripts "md5_test_oo.pl" and "md5_test_func.pl" output the following results:
%perl md5_test_func.pl
test
md5($data) = ?kÍF!ÓsÊÞN&'´ö
md5_hex($data) = 098f6bcd4621d373cade4e832627b4f6
md5_base64($data) = CY9rzUYh03PK3k6DJie09g
%perl md5_test_oo.pl
test
$ctx->digest = ?kÍF!ÓsÊÞN&'´ö
$ctx->hexdigest = d41d8cd98f00b204e9800998ecf8427e
$ctx->b64digest = 1B2M2Y8AsgTpgAmY7PhCfg
while the digest data is the same for both cases the hexdigest and base64 digest data is different. Can you please explain why.
----8<----
%more md5_test_func.pl
#!/usr/bin/perl
use Digest::MD5 qw(md5 md5_hex md5_base64);
my $data = "test";
print "$data\n";
$digest = md5($data);
print "md5(\$data) =\t$digest\n";
$digest = md5_hex($data);
print "md5_hex(\$data) =\t$digest\n";
$digest = md5_base64($data);
print "md5_base64(\$data) =\t$digest\n";
----8<----
%more md5_test_oo.pl
#!/usr/bin/perl
use Digest::MD5;
my $data = "test";
print "$data\n";
$ctx = Digest::MD5->new;
$ctx->add($data);
$digest = $ctx->digest;
print "\$ctx->digest =\t$digest\n";
$digest = $ctx->hexdigest;
print "\$ctx->hexdigest =\t$digest\n";
$digest = $ctx->b64digest;
print "\$ctx->b64digest =\t$digest\n";
%uname -a
FreeBSD 4.5-STABLE FreeBSD 4.5-STABLE #0: Fri Mar 15 16:48:57 EST 2002 root@pc056945.ins.gu.edu.au:/u1/usr/obj/u1/usr/src/sys/GENERIC i386
-Brook