```{index} single: add; Digest::SHA function ``` ```{index} single: Digest::SHA::add; Perl function ``` # add Feed byte data into a `Digest::SHA` object incrementally. Appends each argument to the running hash in order. Use `add` when the data does not fit comfortably in memory, when you are assembling the message from many sources, or when you want to branch the computation via `clone`. Calling `add($a, $b, $c)` is equivalent to calling `add($a)->add($b)->add($c)` or to calling `add($a . $b . $c)`. Arguments are treated as byte strings via `SvPVbyte` semantics: raw bytes pass straight through, UTF-8 strings are downgraded to Latin-1 bytes, and wide characters (codepoint above `255`) croak. ## Synopsis ```perl $sha->add($data); $sha->add(@chunks); $sha->add($a)->add($b)->add($c); ``` ## What you get back The receiver, so calls chain. ## Examples ```perl my $sha = Digest::SHA->new(256); $sha->add("abc"); print $sha->hexdigest; ## ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad ``` ```perl my $sha = Digest::SHA->new(512); while (defined(my $line = <$fh>)) { $sha->add($line); } print $sha->hexdigest; ``` ```perl my $sha = Digest::SHA->new(256); $sha->add("a", "b", "c"); ## identical to $sha->add("abc") ``` ## Edge cases - Empty strings are silently absorbed with no effect on the hash. - A wide character in any argument croaks with `Wide character in subroutine entry`; encode to UTF-8 explicitly before `add` if you want to hash non-Latin-1 text. - Called on an object that is not a `Digest::SHA`, returns `undef`. ## Differences from upstream Fully compatible with upstream `Digest::SHA` {{ upstream.Digest_SHA }}. ## See also - `addfile` — feed a filehandle or filename directly, avoiding a read loop. - `add_bits` — hash a sub-byte number of bits. - `digest` — finalise and return the hash once all data is fed.