I'm not sure get_layers is the best way to get the name of the locale's encoding, but assuming it is, this works: (Perl 5.8.2 linux)
use open ':locale';
use Encode;
use strict;
my $locEnc;
for (PerlIO::get_layers(STDOUT)){
if (/encoding\((.*)\)/ || /(utf8)/ ){
$locEnc=$1;last;
}
}
print "Locale encoding: $locEnc\n";
for (@ARGV) {
$_=Encode::decode($locEnc,$_)
}
my $i=1;
for (@ARGV) {
print $i++," '",$_,"'(",length($_),")\n";
}
It decodes (in place) each command-line argument from the locale's encoding, then prints them alongside their length. This helps in understanding what kind of strings Perl thinks it is working with.