Perlでmd5sum(ファイルのmd5ハッシュ値を求める)

md5.pl
#!/usr/bin/perl
use strict;
use warnings;
use Digest::MD5;

my $file = shift;
open my $fh, "<", $file;
print Digest::MD5->new->addfile($fh)->hexdigest , "\n";
close $fh;
実行結果
$ md5.pl hello.txt
b1946ac92492d2347c6235b4d2611184
なお、Perlを使わずにLinuxコマンドでやる場合はmd5sumコマンドを使います。
$ md5sum hello.txt
b1946ac92492d2347c6235b4d2611184 hello.txt
カテゴリ: