Skip to content

Instantly share code, notes, and snippets.

@fand fand/md5.pl
Created Jan 31, 2014

Embed
What would you like to do?
Digest::MD5 hex digest ???
use strict;
use warnings;
use utf8;
use Encode;
use Digest::MD5;
use v5.010;
my $str = 'ジムに行き筋肉ムキムキ';
# OOP style
my $ctx = Digest::MD5->new;
$ctx->add(encode_utf8 $str);
say 'OOP : ' . $ctx->hexdigest;
# => OOP : ad9049eb074cfb67c84cf444097fdf7d
# Functional style
say 'Func: ' . Digest::MD5->md5_hex(encode_utf8 $str);
# => Func: ee8b1a5de3a63dd3dfe50488088af2bb
use strict;
use warnings;
use utf8;
use Digest::MD5;
use v5.010;
my $data = pack('i3', 1, 2, 3);
# OOP style
my $ctx = Digest::MD5->new;
$ctx->add($data);
say 'OOP style : ' . $ctx->hexdigest;
# => OOP : 2a1dd1e1e59d0a384c26951e316cd7e6
# Functional style
say 'Func style: ' . Digest::MD5->md5_hex($data);
# => Func: f258168ffea40d1bf16a631eb87b07f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.