Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change accented characters to lower case using Perl

Tags:

perl

I have set of accented characters like this

<code>enter image description here</code>

I want to convert upper case accented characters to lower case. I used the lc operator, but I can't get the expected output.

For example, I want to convert  to â.

If I take an XML entity like &#x00C2, if I converted it to lower case it should become &#x00E2

like image 200
depsai Avatar asked Dec 26 '22 06:12

depsai


1 Answers

#!/usr/bin/perl
use warnings;
use strict;
use Encode qw(encode decode);

my $enc = 'utf-8'; # This script is stored as UTF-8
my $str = "Ä\n";

# Byte strings:
print lc $str; # prints 'Ä', lc didn't have any effect

# text strings::
my $text_str = decode($enc, $str);
$text_str = lc $text_str;
print encode($enc, $text_str); # prints 'ä', lc worked as expected

Try it this may work.

like image 61
parthi Avatar answered Jan 20 '23 13:01

parthi