perl-utf8

In a utf8-clean environment, you have to take some actions to ensure good exchanges with other parts of you information system (eg. STDOUT, or a mysql database). Below is summary:

Summary:

In a utf8-clean environment, you still need both of these:

To actually convert data from and to utf8, e.g. when you get data in strange encodings from external sources, use the methods in the "Encode" library: <pre class"example"> "use Encode;"

1 envoking right: perl -C or $PERL_UNICODE

$ perl -C

The -C option is required to make perl globally assume UTF-8 on STDIN and provide it on STDOUT. Perhaps more convenient then setting the -C option, is defining the corresponding enviroment variable, here's an example of /etc/environment:

LANG="C"
LC_ALL="sv_SE.utf8"
PERL_UNICODE=""

http://perldoc.perl.org/perlrun.html#ENVIRONMENT

dbd::mysql

Q: What good does "mysql_enable_utf8 > 1" bring me? A: It makes it possible for perl (from dbd::mysql version 4.001 and higher) to communicate with a mysql-database which uses utf8 and non-ascii characters **in column or table names** <pre class"example"> $dbh = DBI->connect($dsn, $username, $password, {mysql_enable_utf8 => 1}) || die "Could not connect to $database: $DBI::errstr"; $sth = $dbh->prepare("select kön from Kön where id = '1'") || die "Could not prepare statement: ".$dbh->errstr."\n";

It should also mark incomming UTF-8 data retreived from mysql as utf8 for perl internally, but does not due to a bug in libdbd-mysql-perl.

Using perl -C is a workaround for this.

Encode

To convert data to and from utf8:

use Encode;

Even if you have a utf8-only system, you need Encode if data from external sources are not utf8 encoded.

use utf8;

Only needed when you want variable names with utf8 characters, eg

my $förälder = "foo";
print $förälder;

comments powered by Disqus


Back to the index

Blog roll

R-bloggers, Debian Weekly
Valid XHTML 1.0 Strict [Valid RSS] Valid CSS! Emacs Muse Last modified: oktober 17, 2019