{
    "mode": "perldoc",
    "parameter": "Digest::MD5::File",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Digest%3A%3AMD5%3A%3AFile/json",
    "generated": "2026-06-11T19:09:48Z",
    "synopsis": "use Digest::MD5::File qw(dirmd5hex filemd5hex urlmd5hex);\nmy $md5 = Digest::MD5->new;\n$md5->addpath('/path/to/file');\nmy $digest = $md5->hexdigest;\nmy $digest = filemd5($file);\nmy $digest = filemd5hex($file);\nmy $digest = filemd5base64($file);\nmy $md5 = Digest::MD5->new;\n$md5->addurl('http://www.tmbg.com/tour.html');\nmy $digest = $md5->hexdigest;\nmy $digest = urlmd5($url);\nmy $digest = urlmd5hex($url);\nmy $digest = urlmd5base64($url);\nmy $md5 = Digest::MD5->new;\n$md5->adddir('/directory');\nmy $digest = $md5->hexdigest;\nmy $dirhashref = dirmd5($dir);\nmy $dirhashref = dirmd5hex($dir);\nmy $dirhashref = dirmd5base64($dir);",
    "sections": {
        "NAME": {
            "content": "Digest::MD5::File - Perl extension for getting MD5 sums for files and urls.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Digest::MD5::File qw(dirmd5hex filemd5hex urlmd5hex);\n\nmy $md5 = Digest::MD5->new;\n$md5->addpath('/path/to/file');\nmy $digest = $md5->hexdigest;\n\nmy $digest = filemd5($file);\nmy $digest = filemd5hex($file);\nmy $digest = filemd5base64($file);\n\nmy $md5 = Digest::MD5->new;\n$md5->addurl('http://www.tmbg.com/tour.html');\nmy $digest = $md5->hexdigest;\n\nmy $digest = urlmd5($url);\nmy $digest = urlmd5hex($url);\nmy $digest = urlmd5base64($url);\n\nmy $md5 = Digest::MD5->new;\n$md5->adddir('/directory');\nmy $digest = $md5->hexdigest;\n\nmy $dirhashref = dirmd5($dir);\nmy $dirhashref = dirmd5hex($dir);\nmy $dirhashref = dirmd5base64($dir);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Get MD5 sums for files of a given path or content of a given url.\n",
            "subsections": []
        },
        "EXPORT": {
            "content": "None by default. You can export any file* dir*, or url* function and anything Digest::MD5 can\nexport.\n\nuse Digest::MD5::File qw(md5 md5hex md5base64); # 3 Digest::MD5 functions\nprint md5hex('abc123'), \"\\n\";\nprint md5base64('abc123'), \"\\n\";\n",
            "subsections": []
        },
        "OBJECT METHODS": {
            "content": "addpath()\nmy $md5 = Digest::MD5->new;\n$md5->addpath('/path/to/file.txt')\nor die \"file.txt is not where you said: $!\";\n\nor you can add multiple files by specifying an array ref of files:\n\n$md5->addpath(\\@files);\n\nadddir()",
            "subsections": [
                {
                    "name": "addpath",
                    "content": "my $md5 = Digest::MD5->new;\n$md5->adddir('/home/tmbg/')\nor die \"See warning above to see why I bailed: $!\";\n\naddurl()\nmy $md5 = Digest::MD5->new;\n$md5->addurl('http://www.tmbg.com/tour.html')\nor die \"They Must Be not on tour\";\n\nfile* functions\nGet the digest in variouse formats of $file. If file does not exist or is a directory it croaks\n(See NOFATALS for more info)\n\nmy $digest = filemd5($file) or warn \"$file failed: $!\";\nmy $digest = filemd5hex($file) or warn \"$file failed: $!\";\nmy $digest = filemd5base64($file) or warn \"$file failed: $!\";\n\ndir* functions\nReturns a hashref whose keys are files relative to the given path and the values are the MD5 sum\nof the file or and empty string if a directory. It recurses through the entire depth of the\ndirectory. Symlinks to files are just addpath()d and symlinks to directories are followed.\n\nmy $dirhashref = dirmd5($dir) or warn \"$dir failed: $!\";\nmy $dirhashref = dirmd5hex($dir) or warn \"$dir failed: $!\";\nmy $dirhashref = dirmd5base64($dir) or warn \"$dir failed: $!\";\n\nurl* functions\nGet the digest in various formats of the content at $url (Including, if $url points to\ndirectory, the directory listing content). Returns undef if url fails (IE if LWP::UserAgent's\n$res->issuccess is false)\n\nmy $digest = urlmd5($url) or warn \"$url failed\";\nmy $digest = urlmd5hex($url) or warn \"$url failed\";\nmy $digest = urlmd5base64($url) or warn \"$url failed\";\n"
                }
            ]
        },
        "SPECIAL SETTINGS": {
            "content": "BINMODE\nBy default files are opened in binmode. If you do not want to do this you can unset it a variety\nof ways:\n\nuse Digest::MD5::File qw(-nobin);\n\nor\n\n$Digest::MD5::File::BINMODE = 0;\n\nor at the function/method level by specifying its value as the second argument:\n\n$md5->addpath($file,0);\n\nmy $digest = filemd5hex($file,0);\n\nUTF8\nIn some cases you may want to have your data utf8 encoded, you can do this the following ways:\n\nuse Digest::MD5::File qw(-utf8);\n\nor\n\n$Digest::MD5::File::UTF8 = 1;\n\nor at the function/method level by specifying its value as the third argument for files and\nsecond for urls:\n\n$md5->addpath($file,$binmode,1);\n\nmy $digest = filemd5hex($file,$binmode,1);\n\n$md5->addurl($url,1);\n\nurlmd5hex($url,1);\n\nIt use's Encode's encodeutf8() function to do the encoding. So if you do not have Encode (pre\n5.7.3) this won't work :)\n\nNOFATALS\nInstead of croaking it will return undef if you set NOFATALS to true.\n\nYou can do this two ways:\n\n$Digest::MD5::File::NOFATALS = 1;\n\nor the -nofatals flag:\n\nuse Digest::MD5::File qw(-nofatals);\n\nmy $digest = filemd5hex($file) or die \"$file failed\";\n\n$! is not set so its not really helpful if you die().\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Digest::MD5, Encode, LWP::UserAgent\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Daniel Muey, <http://drmuey.com/cpancontact.pl>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "Copyright 2005 by Daniel Muey\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "Digest::MD5::File - Perl extension for getting MD5 sums for files and urls.",
    "flags": [],
    "examples": [],
    "see_also": []
}