Andre_br has asked for the wisdom of the Perl Monks concerning the following question:

Oh, Holly Wisdom!

Hello my friends,

I´m having trouble making Perl to understand that the strings I´m trying to convert from upper to lower case aren´t in english. The result is that all the letters with accents remain in upper case. Ex: É remains É

I´ve searched the web for this topic but the locale function seems like a whole book to read. Can anyone help me out on this? My website is in portuguese, but I think any setup that handles accents will do, like french, for example.

Thanks a lot!

André

  • Comment on Setting Locale for non-english language

Replies are listed 'Best First'.
Re: Setting Locale for non-english language
by sh1tn (Priest) on Jan 31, 2005 at 14:53 UTC
    You have to use
    use locale; use POSIX 'locale_h'; my $locale = 'Bulgarian_Bulgaria.1251'; # get the current locale my $org_locale = setlocale(LC_CTYPE); # set the current locale setlocale(LC_CTYPE, $locale) or die "Invalid locale $locale"; # do some work like $words = ucfirst$word; # set again the original locale setlocale(LC_CTYPE, $org_locale) or die "Invalid locale $org_locale";
Re: Setting Locale for non-english language
by fglock (Vicar) on Jan 31, 2005 at 14:58 UTC

    Oi andre_br - isso aqui funcionou para mim no Debian (en: Hi andre_br, this works in Debian):

    $ perl -v This is perl, v5.8.4 built for i386-linux-thread-multi $ perl -MEncode -e ' my $n = "ANDRÉ"; my $utf8 = decode( "iso-8859-1", + $n ); print $utf8, " ", lc( $utf8 ); ' ANDRÉ andré
      Hello lidden, sh1tn and fglock!

      Lidden, I swear I looked into perldoc, but I really can´t find the information clearly explained. Can´t find the key descriptions of the standards.

      Sh1tn, does 'Bulgarian_Bulgaria.1251' work for accent languages or you gave it just as an example of the syntax?

      Hey fglock! Nice to hear from other brazilian perlmonk! (Where are you located?) Thanks for the tip, but I see that you´re using a command line solution. But I really need a scripting one. You know about this?

      André

        Just change it to:

        use Encode; my $n = "ANDRÉ"; my $utf8 = decode( "iso-8859-1", $n ); print $utf8, " ", lc( $utf8 );

        Where are you located?

        Here. See Brasil-PM for our site. We have a very active mailing list.

Re: Setting Locale for non-english language
by lidden (Curate) on Jan 31, 2005 at 14:35 UTC
    See "perldoc perllocale"