d:\temp\source\test2
d:\temp\source\test5
####
#!d:\perl\bin\perl.exe -w
use File::Find;
use strict;
use Encode qw(encode_utf8 decode_utf8 is_utf8);
use XML::Simple;
my $configfile=".\\config.xml";
my $config=XMLin($configfile);
my $srcdir="d:\\temp\\source\\test2";
print "\$srcdir: $srcdir\n";
if(is_utf8($srcdir)){
print "is utf8\n";
}else{
print "is NOT utf8\n";
$srcdir=decode_utf8($srcdir); # ???
}
# line "!!!" get srcdir from xml
# or you can comment it to test
# wether line "???" take any effect or not
$srcdir=$$config{'srcdir'}; # !!!
if(is_utf8($srcdir)){
print "is utf8\n";
}else{
print "is NOT utf8\n";
}
{
local ${^WIDE_SYSTEM_CALLS} = 1;
finddepth( \&showme, $srcdir );
}
sub fixutf8 {
for (@_) {
if (${^WIDE_SYSTEM_CALLS} && !is_utf8($_)) {
$_ = decode_utf8($_);
}
}
}
sub showme {
print "\$_ = $_\n";
fixutf8($File::Find::dir,$File::Find::name,$_);
print "\$_ = $_\n";
}
####
D:\temp\source>newcopy6.pl
$srcdir: d:\temp\source\test2
is NOT utf8
is utf8
Can't cd to (d:\temp\source\test2/) öa: No such file or directory
at D:\temp\source\newcopy6.pl line 28
$_ = ├╢a
$_ = ├╢a
$_ = .
$_ = .
####
$srcdir: d:\temp\source\test2
is NOT utf8
is utf8
$_ = öa
$_ = öa
$_ = .
$_ = .
####
$srcdir: d:\temp\source\test2
is NOT utf8
is NOT utf8
$_ = ü.txt
$_ = 쯴xt
$_ = öa
$_ = 硍
$_ = .
$_ = .
####
sub fixutf8 {
for (@_) {
print "\$_=$_";
if (${^WIDE_SYSTEM_CALLS} && !is_utf8($_)) {
$_ = decode_utf8($_);
}
if(is_utf8($_)){
print "#\$_=$_ is utf8\n";
}else{
print "#\$_=$_ is NOT utf8\n";
}
}
}
####
$srcdir: d:\temp\source\test2
is NOT utf8
is NOT utf8
$_ = ü.txt
$_=d:\temp\source\test2/öa#$_=d:\temp\source\test2/硠is utf8
$_=d:\temp\source\test2/öa/ü.txt#$_=d:\temp\source\test2/硯쯴xt is utf8
$_=ü.txt#$_=쯴xt is utf8
$_ = 쯴xt
$_ = öa
$_=d:\temp\source\test2#$_=d:\temp\source\test2 is NOT utf8
$_=d:\temp\source\test2/öa#$_=d:\temp\source\test2/硠is utf8
$_=öa#$_=硠is utf8
$_ = 硍
$_ = .
$_=d:\temp\source\test2#$_=d:\temp\source\test2 is NOT utf8
$_=d:\temp\source\test2#$_=d:\temp\source\test2 is NOT utf8
$_=.#$_=. is NOT utf8
$_ = .