Re: Unicode filenames on NTFS using Perl
Michael Ludwig <[email protected]> Tue, 10 Jan 2012 23:16:28 +0100
| Newsgroups | gmane.comp.lang.perl.active-perl |
|---|---|
| Message-ID | <20120110221628.GD7312@Dago> |
Michael Ludwig schrieb am 07.01.2012 um 21:04 (+0100):
> How do you save a file with a Chinese or other name requiring
> Unicode using Active Perl?
> my $chars = 'Катюша'; # say length $chars;
>
> my $count = 0;
> for ( '', qw/UTF-16 UTF-16BE UTF-16LE UTF-8/ ) {
> say 'encoding: ', $_;
> my $n1 = $chars . '.' . ++$count . '.txt';
> my $n2 = $_ ? encode( $_, $n1 ) : $n1;
> if ( open my $fh, '>:encoding(UTF-16)', $n2 ) {
None of these approaches using open() will work correctly with
ActiveState Perl.
What will work is the method detailed here:
How do I create a Unicode directory on Windows using Perl?
http://stackoverflow.com/a/2185032 - Feb 2 '10 - Sinan Ünür
To summarize: use Win32.pm or Win32::API.
use utf8;
use strict;
use warnings;
use Win32;
# chcp 65001
# binmode STDOUT, ':encoding(UTF-8)';
# binmode STDERR, ':encoding(UTF-8)';
for ( qw/ Волгогра́д москва / ) {
Win32::CreateDirectory( $_ ) or warn "CreateDirectory $_: $^E";
}
So use one of those modules for ActiveState Perl
and just straight open() for Cygwin.
Michael
> Cygwin perl 5.10.1, by the way, displayed no errors and got it right:
>
> 07.01.2012 20:51 16 Катюша.1.txt
> 07.01.2012 20:51 16 Катюша.5.txt
>
> You can feed either a character string or a UTF-8 octet string to this
> Cygwin perl.exe open() and it creates the proper filename, proving
> that it's not technically impossible. :)
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs