Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Perl path directory greek

by welle (Beadle)
on Nov 20, 2010 at 09:36 UTC ( #872657=perlquestion: print w/ replies, xml ) Need Help??
welle has asked for the wisdom of the Perl Monks concerning the following question:

Hello!

I am a sort of newbe in Perl and maybe I am missing something very simple. On a Windows machine (XP) I am trying to access files (txt, hmtl, etc.) stored in folders which contain no english characters (it's greek). The path is not hard coded but is selected through (getSaveFile or getOpenFile).

My path is

C:\Documents and Settings\OT\Desktop\ελληνικά

Let's say I want to save a file in this folder. I have:

sub saving { my $path = $mw->getSaveFile(-initialfile => 'text', -defaultextension => '.txt'); open (OUT, ">$path ") or die $!; print OUT "Hello World!"; close OUT; }

I get the following error: TK::Error No such a file or directory. I found this node http://perlmonks.com/?node_id=872508 but it isnot helping me very much as it creates a new folder (and saves the file inside it).

The problem is obviously of encoding nature... but what should I do to work with Perl/Windos on a "non english speaking" machine?

Thank you for your help. Otto

Comment on Perl path directory greek
Download Code
Re: Perl path directory greek
by zentara (Archbishop) on Nov 20, 2010 at 18:19 UTC
Re: Perl path directory greek
by Burak (Chaplain) on Nov 20, 2010 at 22:22 UTC

      Looks promising, but the documentation reads more like chinese than english, and the code still has some strange lines (see below). Use with caution.

      Problems I see from looking at the code of v0.24:

      • In Win32::Unicode::Console::_ConsoleOut(), warn is called. I think that line should print STDERR instead, but I'm not 100% sure.
      • Several functions (Win32::Unicode::Console::dieW(), Win32::Unicode::Console::warnW(), Win32::Unicode::Dir::_croakW, Win32::Unicode::File::_croakW, Win32::Unicode::File::_carpW) call Win32::Unicode::Console::_row_warn() before warn()ing or die()ing, which calls Win32::Unicode::Console::_ConsoleOut() and thus may call warn(), causing repeated or additional calls to a $SIG{__WARN__} handler.
      • In Win32::Unicode::Constant: TRUE and FALSE, oh well. INFINITE is 0xFFFFFFFF? And what magic numbers hide in sub CONSOLE_OUTPUT_HANDLE() { +{7  => 1, 11 => 1, 15 => 1} } and sub CONSOLE_ERROR_HANDLE() { +{11 => 1, 15 => 1} }?
      • Win32::Unicode::Error::errorW() should perhaps call format_message(), not foramt_message(). Nope, the same typo is in Error.xs.
      • Win32::Unicode::Util::to64int() hides a use bigint, should have gone since 0.23 according to the Changes file. Perhaps this was meant to be require bigint?
      • $Win32::Unicode::Process::SHELL may be initialised to a constant C:/WINDOWS/system32/cmd.exe, even if Windows is installed elsewhere (C:\WinNT was common for NT 4 and W2K).
      • Win32::Unicode::Process::_create_process() does some strange things with quotes and the command shell instead of calling the native CreateProcessA()/CreateProcessW() functions. Even the author thinks that code might open a security hole. Both Win32::Unicode::Process::systemW() and Win32::Unicode::Process::execW() wrap this function.
      • Loading Win32::Unicode::Native erases the @ARGV array and replaces it with postprocessed values returned by CommandLineToArgvW(), including some special cases for "-e", "-", and $0. I think it may be possible to confuse the code, so that @ARGV ends up with too many or too few arguments (UNTESTED). For Perl >= 5.10, the code lacks special processing for "-E". And for binaries loading perl5xx.dll instead of invoking perl.exe, the code may become completely confused (UNTESTED).
      • Also in Win32::Unicode::Native: sub __FILE__ () { $script } looks very strange. Was that meant to replace __FILE__ in main?
      • Win32::Unicode::File::open() does not support layers ( la open my $f,'<:utf8',$name). It also does not support pipes (this is documented).
      • Win32::Unicode::File::filename_normalize() replaces several characters in filenames with other strange characters (see %win32_taboo).

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Perl path directory greek
by afoken (Parson) on Nov 20, 2010 at 22:47 UTC

    For perl, filenames are just byte streams, unless you explicitly configure perl to think differently of filenames. On 32 bit Windows (and I think also on 64 bit Windows), perl (both Strawberry and Activestate) is traditionally compiled as a legacy application calling the old "ANSI" API, not capable of handling Unicode (as far as I know). That's quite unfortunate. Perl can handle Unicode properly since at least 5.8.1, and most 32 Bit Windows variants have a Unicode API (all of those DLL exports ending with a "W"), unlike many other operating systems. (See also Re^7: any use of 'use locale'? (source encoding)).

    Look what you get back from getSaveFile(). Dump the Unicode flag of $path, dump the length (if you get back a byte stream, the length exceeds the number of characters with your directory name), dump the character codes (ord()) of each character. Feel free to use some code from UChelp.pm, especially the dumpstr() function.

    Compare that with what you get from a readdir() in C:\Documents and Settings\OT\Desktop.

    Try to make some sense from that, try to convert what you get from getSaveFile() to what readdir() returned. Encode can help you with that.

    Apart from that, every file on Win32 has two names (unless you change some settings). A "long" name that may contain white space and strange characters, and a "short" name that is restricted to DOS-compatible 8.3 notation and very few characters (a subset of ASCII, I think). Using the "short" name could help you.

    Also look at the "W" functions of Win32API::File.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://872657]
Approved by Old_Gray_Bear
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2014-12-19 06:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (72 votes), past polls