Is there a way to uppercase accented characters in Perl?
my $string = "éléphant";
print uc($string);
So that it actually prints ÉLÉPHANT?
My Perl script is encoded in ISO-8859-1 and $string is printed in an XML file with the same encoding.
perl only understands US-ASCII[1] and UTF-8,[2] and the latter requires
use utf8;
If you want to keep the file as iso-8859-1, you'll need to decode the text explicitly.
use open ':std', ':encoding(locale)';
use Encode qw( decode );
# Source is encoded using iso-8859-1, so we need to decode ourselves.
my $string = decode("iso-8859-1", "éléphant");
print uc($string);
But it's probably better to convert the script to UTF-8.
use utf8; # Source is encoded using UTF-8
use open ':std', ':encoding(locale)';
my $string = "éléphant";
print uc($string);
If you're printing to a file, make sure you use :encoding(iso-8859-1) when you open the file (no matter which alternative you use).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With