```{index} single: new; Digest::MD5 function ``` ```{index} single: Digest::MD5::new; Perl function ``` # new Create a fresh MD5 context object, or reset an existing one to empty. ## Synopsis ```perl my $ctx = Digest::MD5->new; # class method — new empty context $ctx->new; # instance method — reset in place ``` ## What you get back A blessed `Digest::MD5` reference whose internal state is the MD5 initial vector — i.e. the digest of the empty string is `md5("")`. Called on an existing instance, `new` resets that instance and returns it; no second object is allocated. The common idiom `Digest::MD5->new->add($data)->hexdigest` relies on this chaining. ## Examples Fresh context, then feed and finalise: ```perl my $ctx = Digest::MD5->new; $ctx->add("hello"); print $ctx->hexdigest; # 5d41402abc4b2a76b9719d911017c592 ``` Reset an existing context instead of allocating a new one: ```perl $ctx->add("round 1")->hexdigest; # digest + auto-reset $ctx->new; # explicit reset (idiomatic no-op here) $ctx->add("round 2"); ``` Chain straight through in one expression: ```perl my $hex = Digest::MD5->new->add("foo", "bar")->hexdigest; ``` ## Edge cases - Called on a subclass name, `new` blesses into that subclass, so `MyDigest->new` returns a `MyDigest` object whose internals are a `Digest::MD5` context. - Called as an instance method, the same object is returned — the caller's variable is unchanged. ## Differences from upstream Fully compatible with upstream `Digest::MD5` {{ upstream.Digest_MD5 }}. ## See also - `clone` — copy the current context instead of resetting it - `reset` — explicit alias for the instance-method form of `new` - `add` — feed data into the context you just created - `hexdigest` — common companion call for one-shot chained use