Skip to Main Content
Perl in a Nutshell, 2nd Edition
book

Perl in a Nutshell, 2nd Edition

by Nathan Patwardhan, Ellen Siever, Stephen Spainhour
June 2002
Beginner content levelBeginner
759 pages
80h 42m
English
O'Reilly Media, Inc.
Content preview from Perl in a Nutshell, 2nd Edition

Digest::MD5

The Digest::MD5 module allows simpler creation of MD5 hashes. MD5 takes as input a message of arbitrary length and creates a 128-bit fingerprint, or digest, of the input. Like the Digest module, Digest::MD5 implements both a functional and object-oriented interface, which offer the same benefits. Digest::MD5 also outputs binary (16 bytes long), hexadecimal (32 characters long), and base64 (22 characters long) data.

To rewrite the example in Section 8.57:

#!/usr/local/bin/perl -w
# Yes, functional interface
use Digest::MD5 qw(md5_hex);

my $text = `Be the ball, Danny!';
my $hexed = md5_hex($text);
 
print "The sum of \$text is [$hexed].\n";

You can use the object-oriented interface like so:

#!/usr/local/bin/perl -w
 
use Digest::MD5;
 
my $text = `Be the ball, Danny!';
my $md5 = Digest::MD5->new();

$md5->add($text);
 
my $sum = $md5->hexdigest;
print "The sum of \$text is [$sum].\n";

Digest::MD5 implements (and exports) the following functions.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl by Example, Fourth Edition

Perl by Example, Fourth Edition

Ellie Quigley
Perl Cookbook, 2nd Edition

Perl Cookbook, 2nd Edition

Tom Christiansen, Nathan Torkington
Perl in a Nutshell

Perl in a Nutshell

Nathan Patwardhan, Ellen Siever, Stephen Spainhour
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 0596002416Errata Page