reset#

Clear an existing context so it behaves like a freshly created one.

Synopsis#

$ctx->reset;                     # discard accumulated data
$ctx->reset->add($data);         # reset and keep going in one line

What you get back#

The same object, returned so calls chain. After reset, the internal state is identical to Digest::MD5->new: accumulated length is zero, the four state words hold the MD5 initial vector, and the partial-block buffer is empty. No new allocation happens — the existing MD5_CTX is overwritten in place.

reset is an alias for the instance-method form of new, exposed as a separate method for readability. Use whichever reads better at the call site.

Examples#

Reuse a context across independent digests:

my $ctx = Digest::MD5->new;
my $h1  = $ctx->add("first")->hexdigest;    # digest + implicit reset
my $h2  = $ctx->add("second")->hexdigest;   # starts fresh

Explicit reset after a partial computation you want to throw away:

$ctx->add("oops, wrong data");
$ctx->reset;
$ctx->add($correct_data);
print $ctx->hexdigest;

Edge cases#

  • Calling reset on a fresh context is a harmless no-op.

  • Reset does not change the class of the object, so subclasses remain blessed into the subclass after a reset.

Differences from upstream#

Fully compatible with upstream Digest::MD5 2.58.

See also#

  • new — same effect when called as an instance method

  • digest — implicitly resets after returning the digest

  • add — the usual next step after reset