I am trying to calculate MD5 from non-Ascii file name and directory name.
For example, if the file name as '零一.txt', the execution will come back with:
Can't call method "addfile" on an undefined value at unicodeTest2.pl line 16.

I am using Activestate perl v5.10.0 build for MSWin32-x86-multi-thread binary build 1003, May 13, 2008
I have the following questions:
1. If the naming system under Windows can be assumed as UTF-8?
2. Am I correct assuming if encoding/decoding is done correctly, the usually Perl package should work for wide-character names
require Encode; use Digest::MD5 qw(md5 md5_hex md5_base64); my $ctx = Digest::MD5->new;; my $where = "C:/0work/test"; open O, ">:utf8", "C:\\0work\\test\\out.txt" or die "Couldn't open STD +OUT: $!" || die "can't open\n"; opendir (D, $where) or print " \ncould not open the directory: $!"; binmode D, ":utf8"; binmode O, ":utf8"; print O "reading the list from the directory $where\n"; my @list = readdir (D); for my $file (sort @list){ next if ! -f $file; print O "$file\n"; open(I,"<$file") || die "couldbn't open $file"; binmode(I, ":utf8"); $ctx->addfile(I); my $digest = $ctx->b64digest; print "digest:", $digest; }
<Updated> added open || die and my $ctx And here is the File::Find portion of my test
use strict; use warnings; use Cwd; use File::Find; use Digest::MD5 qw(md5 md5_hex md5_base64); use File::Basename; require Encode; $|++; my $ctx = Digest::MD5->new; my $totcnt=0; find (&d, "C:/0work/pics/Done"); binmode STDOUT, ":utf8"; sub d { my $file = $File::Find::name; print $file, "\n"; return unless -f $file; open(I,$file); binmode(I); $ctx->addfile(*I); my $digest = $ctx->b64digest; print $file, $digest, "\n"; close(I); }

In reply to MD5 non ascii file name by benjwlee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.