Upper accented characters in perl

Is there a way to capitalize with an inscription in perl,

my $string = "éléphant"; print uc($string); 

So, is he actually printing ÉLÉPHANT?

My perl script is encoded in ISO-8859-1, and the string $ is printed in an XML file with the same encoding.

+3
source share
2 answers

perl only understands US-ASCII and UTF-8, and the latter requires

 use utf8; 

If you want to save the file as iso-8859-1 , you need to explicitly decrypt the text.

 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 best 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 are printing a file, make sure you use :encoding(iso-8859-1) when opening the file (no matter which alternative you use).

+8
source

Try to do this:

 use Encode qw/encode decode/; my $enc = 'utf-8'; # This script is stored as UTF-8 my $str = "éléphant\n"; my $text_str = decode($enc, $str); $text_str = uc $text_str; print encode($enc, $text_str); 

OUTPUT :

 ÉLÉPHANT 
+2
source

Source: https://habr.com/ru/post/956057/


All Articles