I used the suggestions given by "Anonymous Monk" and I managed to find a solution to handle correctly string variables with direct text. Here's the code I created to test some common stuff:
use strict;
use warnings;
use utf8;
use feature 'unicode_strings';
use charnames ':full';
our $base = "c:\\users\\someuser\\documents";
our $dp = "$base\\documentação";
{
my $new_dp = $dp;
my $success = utf8::decode($new_dp);
print "isutf8 test 1: ";
if (utf8::is_utf8($dp)) { print "ok\n"; } else { print "nope\n"; }
print "isutf8 test 2: ";
if (utf8::is_utf8($new_dp)) { print "ok\n"; }
else { print "nope\n"; }
print "-d test 1: ";
if (-d $dp) { print "ok\n"; } else { print "nope\n"; };
print "-d test 2: ";
if (-d $new_dp) { print "ok\n"; } else { print "nope\n"; };
my $dh;
print "opendir test 1: ";
if (opendir($dh, $dp)) { print "ok\n"; close($dh); }
else { print "nope\n"; }
print "opendir test 2: ";
if (opendir($dh, $new_dp)) { print "ok\n"; close($dh); }
else { print "nope\n"; }
my $buf;
print "dir test 1: ";
$buf = `dir /b $dp 2> nul`; chop($buf);
if ($buf ne "") { print "ok\n"; } else { print "nope\n"; }
print "dir test 2: ";
$buf = `dir /b $new_dp 2> nul`; chop($buf);
if ($buf ne "") { print "ok\n"; } else { print "nope\n"; }
my $r;
print "dir test 1: ";
$r = system("dir $dp > nul 2> nul");
if ($r == 0) { print "ok\n"; } else { print "nope\n"; }
print "dir test 2: ";
$r = system("dir $new_dp > nul 2> nul");
if ($r == 0) { print "ok\n"; } else { print "nope\n"; }
}
The output was:
C:\...>perl perlmonks2.pl
isutf8 test 1: ok
isutf8 test 2: nope
-d test 1: nope
-d test 2: ok
opendir test 1: nope
opendir test 2: ok
dir test 1: nope
dir test 2: ok
dir test 1: nope
dir test 2: ok
C:\...>
I will have to do some tests in other computers and with UNC file paths, but it seems that this is it. Now that it is working I can even live with it, but I really hope that future developing on Unicode and Perl can reduce the obscure use of lines of code for doing such simple things.
You guys are great, I wish all the best for who ever try to help.
Experience is the mother of all things, from it we kwnow radicaly the truth -- Duarte Pacheco Pereira, portuguese adventurer and the secret discoverer of America