I still haven't figured out how use open is supposed to work. Hypothesis: it doesn't actually apply the IO layer to your handle. We can test that by querying the IO layers.
use open IO => ":utf8";
while (<>) {
my @layers = PerlIO::get_layers(\*ARGV);
say "(@layers)";
}
If it just outputs something like (unix perlio), it obviously didn't apply the layer.
The explicit way should work, I guess:
use strict;
use warnings;
use autodie;
binmode STDOUT, ":utf8";
for my $file (@ARGV) {
my $fh;
if ($file eq "-") {
$fh = \*STDIN;
binmode $fh, ":utf8";
} else {
open $fh, "<:utf8", $file;
}
while (<$fh>) {
s/[[:ascii:]]//g;
print length, " ", $_, "\n";
}
}