J
Jochen Lehmeier
Hello,
here is a test script that outputs a unicode string which cannot be
represented in latin1 to a latin1-encoded file:
my $unicode="hello \x{010d} world";
binmode STDOUT,":encoding(latin1)";
print $unicode,"\n";
The output of Perl 5.8.8 is:
"\x{010d}" does not map to iso-8859-1 at test.pl line 3.
hello \x{010d} world
So far so good. The output is perfectly fine, as expected.
Is there a way to achieve the output "hello ? world" instead? Having
non-representable characters replaced by the \x{} notation does not help
much, in my case. Non-technical users will not understand this, but they
will understand the "?" (or even latin1-\xbf, the inverse question mark).
Important: I would like to achieve this on the I/O level, either while
opening the file handle, or even with a global setting that catches all
handles opened later. It would be trivial to remove the \x{} using regular
expressions, but that would mean I'd have to make lots of changes to my
scripts.
Thanks in advance!
here is a test script that outputs a unicode string which cannot be
represented in latin1 to a latin1-encoded file:
my $unicode="hello \x{010d} world";
binmode STDOUT,":encoding(latin1)";
print $unicode,"\n";
The output of Perl 5.8.8 is:
"\x{010d}" does not map to iso-8859-1 at test.pl line 3.
hello \x{010d} world
So far so good. The output is perfectly fine, as expected.
Is there a way to achieve the output "hello ? world" instead? Having
non-representable characters replaced by the \x{} notation does not help
much, in my case. Non-technical users will not understand this, but they
will understand the "?" (or even latin1-\xbf, the inverse question mark).
Important: I would like to achieve this on the I/O level, either while
opening the file handle, or even with a global setting that catches all
handles opened later. It would be trivial to remove the \x{} using regular
expressions, but that would mean I'd have to make lots of changes to my
scripts.
Thanks in advance!