hexdigest#
Finalise the context and return the digest as 32 lowercase hex chars.
Synopsis#
my $hex = $ctx->hexdigest; # 32 chars, [0-9a-f]
What you get back#
A 32-character ASCII string containing only 0-9 and a-f. This
is the form you want for ETags, md5sum-style checksum files, log
output, and anywhere humans will read the digest. No 0x prefix,
no separators, lowercase.
hexdigest is destructive: the context is reset to empty after
the digest is produced. Clone first if you need to keep going.
Examples#
Common one-liner:
my $hex = Digest::MD5->new->add("hello")->hexdigest;
## 5d41402abc4b2a76b9719d911017c592
Digest the same context twice by cloning:
$ctx->add("stream so far");
my $checkpoint = $ctx->clone->hexdigest;
$ctx->add("more data");
my $final = $ctx->hexdigest;
Build an md5sum-compatible line:
open(my $fh, '<:raw', $path) or die $!;
printf "%s %s\n", Digest::MD5->new->addfile($fh)->hexdigest, $path;
Edge cases#
Empty context →
d41d8cd98f00b204e9800998ecf8427e(the MD5 of the empty string).The result is always lowercase; if an external format demands uppercase, call
ucon it.Resets the context, so
$ctx->hexdigesttwice without interveningaddcalls gives the empty-string digest the second time.
Differences from upstream#
Fully compatible with upstream Digest::MD5 2.58.
See also#
digest— same content as 16 raw bytesb64digest— shorter base64 encoding of the same digestmd5_hex— one-shot functional formclone— preserve the context before finalising