in reply to How to detect the OS's current encoding?

I'm not sure if I understand the question, but this may help. I asked something similar to this awhile back, where there were encoding problems in finding files in a directory. graff showed me this:
#this decode utf8 routine is used so filenames with extended # ascii characters (unicode) in filenames, will work properly use Encode; opendir my $dh, $path or warn "Error: $!"; my @files = grep !/^\.\.?$/, readdir $dh; closedir $dh; # @files = map{ "$path/".$_ } sort @files; #$_ = decode( 'utf8', $_ ) for ( @files ); @files = map { decode( 'utf8', "$path/".$_ ) } sort @files;
I don't know if Tk's getOpenFile is buggy or not, but graff said that once you pass the filename through decode, Perl will tag it as unicode and do the right thing. Maybe you could make your own "custom-file-dialog" that preprocesses the dirlist with decode?

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: How to detect the OS's current encoding?
by chaoslawful (Acolyte) on Mar 01, 2007 at 15:37 UTC
    I'm afraid making a customized file dialog would not get the encoding problem around, for we still needs to know the OS's current encoding to 'decode' pathname into UTF-8 in order to display them correctly in Tk widgets. Anyway, Tk 804.xx always using UTF-8 string internally.
      I'm still in a state of semi-confusion with all of this encoding stuff. But my understanding of the problem I had, was that the program that saved the file, didn't use the right encoding when it saved the file, so when my local system tried to read it, I would see a 2 letter set, in place of the unicode character. graff's method of decoding it, would automagically convert the filenames to be recognized by my system.

      It isn't hard to make your own custom file selector dialog, and if you do, it would be easy to run decode on the files first. Maybe you could sub-class getOpenFile, to do a decode routine first?

      See Re: problems with extended ascii characters in filenames if you are interested.

      And there is the often given tip, which I don't quite understand

      $Tk::encodeFallback=1

      Then again, I probably don't even understand your problem, :-)


      I'm not really a human, but I play one on earth. Cogito ergo sum a bum