Reputation: 25117
Does the function dir
from IO::Path decode the file-names automatically the right way or is there a possibility to set the encoding?
In Perl5 I mostly follow the recommendation to decode the input and to encode the output.
So for example in Perl5 I would write something like this, if the encoding the OS uses to write the file-names is different from the encoding of the console output.
use Encode::Locale;
use Encode qw(decode);
binmode STDOUT, ':encoding(console_out)';
my @files;
while ( my $file = readdir $dh ) {
push @files, decode( 'locale_fs', $file );
}
for my $file ( @files ) {
print "$file\n";
}
In Perl6 I don't know exactly what I should do.
Upvotes: 3
Views: 106
Reputation: 169573
Perl 6 uses Unicode strings internally (in a grapheme-based representation), and coding happens at the IO boundaries.
For console output, you can manually set the encoding via $*OUT.encoding("...")
.
For directory listings, it depends on the backend: With the JVM, it should do the right things (or fail the same way Java does). With MoarVM, it will depend on the platform: On Win32, the Unicode API is used (which, again, should do the right thing), whereas on other platforms, UTF-8 is assumed. As can be seen from that snippet, the ability to use a different encoding in principle exists at the lowest level, but it does not appear to be exposed to the user in any way...
Upvotes: 1