SlideShare a Scribd company logo
1 of 23
Perl и Unicode Олег Алистратов Perl Mova– 2010
Зачем нужен Unicode?
Unicode в .ru 100 000 случайных сайтов Top 350*сайтов * По данным GoalEurope / Rating of Russian Web 2.0 Companies 2008
История
Трафик: text/plain Увеличение размера кириллического текста на 79%
Трафик: text/html Увеличение размера HTML с русским текстом на 14% Медианный  размер 100 тыс. случайно выбранных русскоязычных страниц
Трафик: gzipped
Производительность: платформы Mobile Intel® Celeron® 560 @ 2.13 GHz, RAM 1 GbMicrosoft® Windows® XP SP3ActiveState Perl v5.10.0 Intel® Core™2 Duo E7400 @ 2.80 GHz, RAM 2 GbUbuntu 9.10 Karmic Koala linux 2.6.31-14-serverperl v5.10.0 Intel® Xeon® E5450 @ 3.00 GHz ×2, RAM 32 GbFreeBSD® 6.2-RELEASE-p3perl v5.8.8
Строковые функции 107% 112% 105 … 172%
Регулярные выражения 120…600% 115% 2100...6500%
Регулярные выражения use re 'debug'; $a =~ //; DIGIT $a =~ /[0-9]/; ANYOF[0-9] $a =~ /(?:0|1|2|3|4|5|6|7|8|9)/; TRIEC-EXACT[0-9]
Исходный файл в UTF-8 { use utf8; my $a = 'Привет!'; print length($a), ""; } > 7 { no utf8; my $a = 'Привет!'; print length($a), ""; } > 13
Символы и байты use utf8; # or use encoding "cp1251"; my $a = 'Привет!'; print length($a), ""; use bytes; print length($a), ""; > 7 > 13 use encoding::warnings 'FATAL';
Исключения chdir, chmod, chown, chroot, exec, link, lstat, mkdir, rename, rmdir, stat, symlink, truncate, unlink, utime, -X %ENV glob (<*>) open, opendir, sysopen qx/…/, system readdir, readlink
Encode use utf8; use Encode; my $x = 'a -> b'; $x = Encode::encode(         'windows-1251',          $x,          Encode::FB_HTMLCREF      ); print $x, ""; > a &#8594; b
Символы my $copy = "00a9";     my $copy = "{00a9}";    my $copy = pack('U', 0x00a9); print $copy; > ©
Регулярные выражения my $copy = '©'; $copy =~ /{00a9}/; $copy !~ /{Uppercase}/; $copy =~ /{Other_Symbol}/; $copy =~ /{InLatin-1_Supplement}/; $copy !~ /{InCyrillic}/; $copy !~ /{BidiClass:R}/;
IO open(my $fh, "<:utf8", "file.txt"); open(my $fh, "<:encoding(UTF-8)", "file.txt"); open(my $fh, "<:encoding(cp1251)", "file.txt"); binmode(STDOUT, ":utf8"); RTFM Encode::Supported
LWP use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $response = $ua->get("http://example.com"); if ($response->is_success) { my $content = $response->decoded_content; if (defined($content)) {         # ...     } }
Базы данных MySQL $dbh->do('SET NAMES utf8'); $dbh->{mysql_enable_utf8} = 1; PostgreSQL $dbh->do("SET client_encoding TO 'UTF8'"); $dbh->{pg_enable_utf8} = 1; SQLite $dbh->{sqlite_unicode} = 1;
Конвертация БД $mysqldumpdb_name > dump.sql $iconv -f cp1251 -t utf-8 dump.sql >  newdump.sql $sed -i .bak "s/cp1251/utf8/"  newdump.sql $mysql < newdump.sql
perl 5.12 Расширена поддержка классов и свойста символов до стандартаUnicode 5.2.0 usecharnames':full'; print"{GREEK SMALL LETTER ALPHA}"
Спасибо! Олег Алистратов http://alienator.ya.ru http://clubs.ya.ru/regexp/

More Related Content

Viewers also liked

Animals
AnimalsAnimals
AnimalsDavid
 
Regular expressions in Perl 5.14
Regular expressions in Perl 5.14Regular expressions in Perl 5.14
Regular expressions in Perl 5.14Oleg Alistratov
 
PROFILO PSICOPROFESSIONALE MARCO COLLA (1) (1)
PROFILO PSICOPROFESSIONALE MARCO COLLA (1) (1)PROFILO PSICOPROFESSIONALE MARCO COLLA (1) (1)
PROFILO PSICOPROFESSIONALE MARCO COLLA (1) (1)Marco Colla
 
Web application scalability
Web application scalabilityWeb application scalability
Web application scalabilityOleg Alistratov
 
PREHISTORIA5º
PREHISTORIA5ºPREHISTORIA5º
PREHISTORIA5ºcpsje56
 

Viewers also liked (8)

Animals
AnimalsAnimals
Animals
 
Regular expressions in Perl 5.14
Regular expressions in Perl 5.14Regular expressions in Perl 5.14
Regular expressions in Perl 5.14
 
PROFILO PSICOPROFESSIONALE MARCO COLLA (1) (1)
PROFILO PSICOPROFESSIONALE MARCO COLLA (1) (1)PROFILO PSICOPROFESSIONALE MARCO COLLA (1) (1)
PROFILO PSICOPROFESSIONALE MARCO COLLA (1) (1)
 
L10N
L10NL10N
L10N
 
Web application scalability
Web application scalabilityWeb application scalability
Web application scalability
 
Web 2 0
Web 2 0Web 2 0
Web 2 0
 
NYFW - Rebecca Taylor
NYFW - Rebecca TaylorNYFW - Rebecca Taylor
NYFW - Rebecca Taylor
 
PREHISTORIA5º
PREHISTORIA5ºPREHISTORIA5º
PREHISTORIA5º
 

Similar to Perl & Unicode

ZFConf 2010: Zend Framework and Multilingual
ZFConf 2010: Zend Framework and MultilingualZFConf 2010: Zend Framework and Multilingual
ZFConf 2010: Zend Framework and MultilingualZFConf Conference
 
PHP basic
PHP basicPHP basic
PHP basicNoveo
 
Что нового в Perl 5.14
Что нового в Perl 5.14Что нового в Perl 5.14
Что нового в Perl 5.14Andrew Shitov
 
Problems of Automated Generation of Exploits on the Basis of Source Code
Problems of Automated Generation of Exploits on the Basis of Source CodeProblems of Automated Generation of Exploits on the Basis of Source Code
Problems of Automated Generation of Exploits on the Basis of Source CodePositive Hack Days
 
ZFConf 2010: Zend Framework and Doctrine
ZFConf 2010: Zend Framework and DoctrineZFConf 2010: Zend Framework and Doctrine
ZFConf 2010: Zend Framework and DoctrineZFConf Conference
 
Интеграция Яндекс Сервер
Интеграция Яндекс СерверИнтеграция Яндекс Сервер
Интеграция Яндекс СерверPVasili
 
Igor Khotin - Domain Specific Languages
Igor Khotin - Domain Specific LanguagesIgor Khotin - Domain Specific Languages
Igor Khotin - Domain Specific LanguagesIgor Khotin
 
Программирование Linux
Программирование LinuxПрограммирование Linux
Программирование LinuxAnthony Shoumikhin
 
Программирование Linux
Программирование LinuxПрограммирование Linux
Программирование LinuxAnthony Shoumikhin
 
Программирование Linux
Программирование LinuxПрограммирование Linux
Программирование LinuxAnthony Shoumikhin
 
Разработка на Perl под Raspberry PI
Разработка на Perl под Raspberry PIРазработка на Perl под Raspberry PI
Разработка на Perl под Raspberry PIIlya Chesnokov
 
Groovy On Grails
Groovy On GrailsGroovy On Grails
Groovy On Grailsguest32215a
 
Выступление Андрея Сумина, Mail.Ru Group, на High Performance Conference
Выступление Андрея Сумина, Mail.Ru Group, на High Performance ConferenceВыступление Андрея Сумина, Mail.Ru Group, на High Performance Conference
Выступление Андрея Сумина, Mail.Ru Group, на High Performance ConferenceEYevseyeva
 
Zen Coding
Zen CodingZen Coding
Zen Coding404fest
 
Saint Perl 2009: CGI::Ajax demo
Saint Perl 2009: CGI::Ajax demoSaint Perl 2009: CGI::Ajax demo
Saint Perl 2009: CGI::Ajax demomegakott
 

Similar to Perl & Unicode (20)

ZFConf 2010: Zend Framework and Multilingual
ZFConf 2010: Zend Framework and MultilingualZFConf 2010: Zend Framework and Multilingual
ZFConf 2010: Zend Framework and Multilingual
 
PHP basic
PHP basicPHP basic
PHP basic
 
Что нового в Perl 5.14
Что нового в Perl 5.14Что нового в Perl 5.14
Что нового в Perl 5.14
 
Perl – жив?!
Perl – жив?!Perl – жив?!
Perl – жив?!
 
Problems of Automated Generation of Exploits on the Basis of Source Code
Problems of Automated Generation of Exploits on the Basis of Source CodeProblems of Automated Generation of Exploits on the Basis of Source Code
Problems of Automated Generation of Exploits on the Basis of Source Code
 
ZFConf 2010: Zend Framework and Doctrine
ZFConf 2010: Zend Framework and DoctrineZFConf 2010: Zend Framework and Doctrine
ZFConf 2010: Zend Framework and Doctrine
 
Интеграция Яндекс Сервер
Интеграция Яндекс СерверИнтеграция Яндекс Сервер
Интеграция Яндекс Сервер
 
Igor Khotin - Domain Specific Languages
Igor Khotin - Domain Specific LanguagesIgor Khotin - Domain Specific Languages
Igor Khotin - Domain Specific Languages
 
Приручаем linux-консоль
Приручаем linux-консольПриручаем linux-консоль
Приручаем linux-консоль
 
Ci
CiCi
Ci
 
Программирование Linux
Программирование LinuxПрограммирование Linux
Программирование Linux
 
Программирование Linux
Программирование LinuxПрограммирование Linux
Программирование Linux
 
Программирование Linux
Программирование LinuxПрограммирование Linux
Программирование Linux
 
Разработка на Perl под Raspberry PI
Разработка на Perl под Raspberry PIРазработка на Perl под Raspberry PI
Разработка на Perl под Raspberry PI
 
Groovy On Grails
Groovy On GrailsGroovy On Grails
Groovy On Grails
 
Выступление Андрея Сумина, Mail.Ru Group, на High Performance Conference
Выступление Андрея Сумина, Mail.Ru Group, на High Performance ConferenceВыступление Андрея Сумина, Mail.Ru Group, на High Performance Conference
Выступление Андрея Сумина, Mail.Ru Group, на High Performance Conference
 
Zen Coding
Zen CodingZen Coding
Zen Coding
 
Saint Perl 2009: CGI::Ajax demo
Saint Perl 2009: CGI::Ajax demoSaint Perl 2009: CGI::Ajax demo
Saint Perl 2009: CGI::Ajax demo
 
Installcd Kyivbsd09
Installcd Kyivbsd09Installcd Kyivbsd09
Installcd Kyivbsd09
 
Yserver
YserverYserver
Yserver
 

Perl & Unicode