ALT Linux Sisyphus discussions
 help / color / mirror / Atom feed
From: "Кокарев Константин" <nwtour-subs@mail.ru>
To: ALT Linux Sisyphus discussions <sisyphus@lists.altlinux.org>
Subject: Re: [sisyphus] perl и unicode
Date: Sat, 12 Apr 2008 02:21:11 +0400
Message-ID: <47FFE457.4000706@mail.ru> (raw)
In-Reply-To: <200804111340.47797.boris@office.etersoft.ru>

Boris Savelev пишет:
> Здравствуйте!
> Столкнулся с проблемой использования юникода в перле, а именно (cgi тест)
> #!/usr/bin/perl -W
> use strict;
> print "Content-type: text/plain; charset=UTF-8\n\n";
> my $text;
> my $text_lc;
> $text="БОЛЬШОЙ!маленький!small!BIG!";
> $text_lc=lc($text);
> print "Env 'PERL_UNICODE' is ";
> print ${^UNICODE};
> print "\n";
> print "Run test: \n";
> print "Source text\n";
> print $text;
> print "\n";
> print "Text after LowerCase\n";
> print $text_lc;
>
> Текст написан в UTF8.
> В таком виде тест не проходит, т.е. большие русские символы маленькими не 
> становятся, хотя с латинскими все прекрасно.
> Далее если в начале добавить:
> use utf8;
> то тест отрабатывается, но:
> Starting from Perl 5.8.0, the use of use utf8  is no longer necessary
> (http://perldoc.perl.org/perluniintro.html)
> rpm -qa | grep perl-base
> perl-base-5.8.8-alt19
> проверялось все это в OVZ-контейнере с apache22
> Был еще нарыт ключик -С к perl, определяющий PERL_UNICODE, но манипуляции с 
> ним ни к чему не привели. Помогите советом, пожалуйста.
>
> Еще хотелось бы спросить чем отличается использование
> use utf8;
> от
> use encode 'utf-8';
> ?
>
> PS: все это как-то всплыло при обнаружении не работающего поиска c 
> использование кирилицы по Bugzilla. Вся багзила в юникоде, база в юникоде, но 
> на этапе передачи параметров, слова поиска "портятся" (из-за двойного 
> перекодирования?) из-за чего поиск ессно не удается. С включенным дебагом 
> запрос выглядит так (ищем слово "привет"):
> SELECT bugs.bug_id, bugs.bug_severity, bugs.priority, bugs.bug_status, 
> bugs.resolution, bugs.bug_severity, bugs.priority, bugs.op_sys, 
> map_assigned_to.login_name, bugs.bug_status, bugs.resolution, 
> bugs.short_desc, (SUM(MATCH(longdescs_.thetext) AGAINST('привет' )) + CASE 
> WHEN bugs.short_desc LIKE '%������%' THEN 7 ELSE 0 END) AS relevance FROM 
> bugs INNER JOIN profiles AS map_assigned_to ON (bugs.assigned_to = 
> map_assigned_to.userid) INNER JOIN longdescs AS longdescs_ ON (bugs.bug_id = 
> longdescs_.bug_id ) LEFT JOIN bug_group_map ON bug_group_map.bug_id = 
> bugs.bug_id AND bug_group_map.group_id NOT IN (13,4,1,10,11,6,2,8,12,5,3,7,9) 
> LEFT JOIN cc ON cc.bug_id = bugs.bug_id AND cc.who = 1 WHERE 
> ((bugs.bug_status IN ('UNCONFIRMED','NEW','ASSIGNED','REOPENED')) AND 
> (MATCH(longdescs_.thetext) AGAINST('привет' ) > 0 OR (bugs.short_desc 
> LIKE '%������%'))) AND bugs.creation_ts IS NOT NULL AND 
> ((bug_group_map.group_id IS NULL) OR (bugs.reporter_accessible = 1 AND 
> bugs.reporter = 1) OR (bugs.cclist_accessible = 1 AND cc.who IS NOT NULL) OR 
> (bugs.assigned_to = 1) ) GROUP BY bugs.bug_id ORDER BY relevance desc LIMIT 
> 200
> Если добавить "use utf8;" в buglist.cgi и в нужный шаблон, то проблема 
> исчезает, но это хак, а хочется понять суть проблемы, может она банальна-)
> Может я все усложнил, но help, help!
>   
Как говорит кэмелбук, перл старше 5.8 воспринимает строку в utf8 если 
вся строка состоит из символов больше 255. В примере это не так.

Сделано для совместимости со старыми скриптами.


-- 
nwtour



  parent reply	other threads:[~2008-04-11 22:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-11  9:40 Boris Savelev
2008-04-11  9:46 ` Boris Savelev
2008-04-11 22:21 ` Кокарев Константин [this message]
2008-04-12 17:17 ` Alexey Tourbin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47FFE457.4000706@mail.ru \
    --to=nwtour-subs@mail.ru \
    --cc=sisyphus@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Sisyphus discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/sisyphus/0 sisyphus/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 sisyphus sisyphus/ http://lore.altlinux.org/sisyphus \
		sisyphus@altlinux.ru sisyphus@altlinux.org sisyphus@lists.altlinux.org sisyphus@lists.altlinux.ru sisyphus@lists.altlinux.com sisyphus@linuxteam.iplabs.ru sisyphus@list.linux-os.ru
	public-inbox-index sisyphus

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.sisyphus


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git