Hi,
I have this little routine that works great at finding and removing bad encoding (for my purposes):
sub _checkit {
my $txt = shift;
use warnings FATAL => 'utf8';
1 until eval {
print "$txt\n";
1;
} or do {
my ($charcode) = $@ =~ /U\+(\S+)/ or die $@;
$txt =~ s/\x{$charcode}//g;
0; # Try again!
};
return ($txt);
}
I have two questions about this:
- I think I understand, but I'd like a good explanation: Why do I need to print to generate/catch the error?
- Is there another way to do this (without print to stdout) so that it doesn't generate all the output? Or should I just redirect stdout to /dev/null?
Thanks!