Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl - Lowercase Accent Letters

Tags:

perl

Using Perl, i'm trying to lowercase words with accents and special chars with lc() but i can't.

For example:

É UM MAÇO

returns

É um maÇo

like image 560
Barata Avatar asked May 03 '11 11:05

Barata


2 Answers

-bash$ perl -we 'use utf8; binmode STDOUT, ":utf8"; print lc "É UM MAÇO"'
é um maço

utf8 indicates your program text is unicode. binmode ensures proper output of wide characters.

You can also use Encode;, see the docs.

like image 85
Dallaylaen Avatar answered Nov 02 '22 05:11

Dallaylaen


Try adding

use locale;

into your script. It should make various functions including lc work with accents. Full testing script:

use strict; use warnings;
use locale;
use utf8;

print lc('É UM MAÇO');    # gives "é um maço"
like image 1
bvr Avatar answered Nov 02 '22 04:11

bvr