|
|
ru.perl- RU.PERL ---------------------------------------------------------------------- From : Andrey Ivanov 2:5020/400 29 Mar 2003 15:22:43 To : All Subject : howto convert utf8 to cp1251? --------------------------------------------------------------------------------
Все так же безуспешно продолжаю бороться с перекодированием строки из
utf8 в ср1251:
#!/usr/bin/perl
use Encode;
$strtmp="некая строка в utf";
Encode::from_to($strtmp, "utf8", "cp1251");
print $strtmp;
в результате получаю бред, что обьясняется комментарием с сайта
http://search.cpan.org/author/DANKOGAI/Encode-1.91/Encode.pm
"CAVEAT: When you run $octets = encode("utf8", $string), then $octets
may not be equal to $string. Though they both contain the same data, the
utf8 flag for $octets is always off. When you encode anything, utf8 flag
of the result is always off, even when it contains completely valid utf8
string. See /"The UTF-8 flag" below. "
При попытке включить флаг utf8:
#!/usr/bin/perl
use Encode;
$strtmp="некая строка в utf";
Encode::_utf8_on($strtmp);
Encode::from_to($strtmp, "utf8", "cp1251");
print $strtmp;
в ответ получаю следующее:
Cannot decode string with wide characters at
/usr/lib/perl5/5.8.0/i386-linux-thread-multi/Encode.pm line 176.
и как с этим бороться?
Спасибо.
--- ifmail v.2.15dev5
* Origin: dso (2:5020/400)
Вернуться к списку тем, сортированных по: возрастание даты уменьшение даты тема автор
Архивное /ru.perl/10142a21f4b56.html, оценка из 5, голосов 10
|