Infelizmente...<br><br><a href="http://perldoc.perl.org/utf8.html">http://perldoc.perl.org/utf8.html</a><br>Do not use this pragma for anything else than telling Perl that your script is written in UTF-8.<br clear="all"><br>
A minha referência atual sobre Perl e UTF-8 é esta (original em russo, não a tradução): <a href="http://translate.google.com/translate?hl=en-US&sl=ru&tl=en&u=http%3A%2F%2Fxpoint.ru%2Fknow-how%2FPerl%2FPodderzhkaUnicode">http://translate.google.com/translate?hl=en-US&sl=ru&tl=en&u=http%3A%2F%2Fxpoint.ru%2Fknow-how%2FPerl%2FPodderzhkaUnicode</a><br>
<br>ABS()<br><br>
<br><br><div class="gmail_quote">2010/10/18 Daniel de Oliveira Mantovani <span dir="ltr"><<a href="mailto:mantovani@perl.org.br">mantovani@perl.org.br</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
2010/10/18 Daniel de Oliveira Mantovani <<a href="mailto:mantovani@perl.org.br">mantovani@perl.org.br</a>>:<br>
<div class="im"><code><br>
my $text;{$/=$\;$text=<>};<br>
sub do_what_I_want {return uc(@_)};<br>
</div> when (detect_utf8($buf)) {<br>
<div class="im"> {<br>
require utf8;<br>
do_what_I_want(...)<br>
}<br>
}<br>
<br>
{ do_what_I_want(...) }<br>
</code><br>
<br>
</div>Agora sim.<br>
<div><div></div><div class="h5"><br>
><br>
> /me ;)<br>
><br>
><br>
> Procura no StackOverflow por Perl e codificação, o briand d foy deu<br>
> uma explicação bem útil.<br>
><br>
> 2010/10/18 Stanislaw Pusep <<a href="mailto:creaktive@gmail.com">creaktive@gmail.com</a>>:<br>
>> Tenho certeza de que o assunto foi levantado várias vezes na lista, então,<br>
>> ATENÇÃO: o Perl tem excelentes mecanismos para tratar I/O em diversas<br>
>> codificações da maneira mais prática possível. Por exemplo, dá para pegar<br>
>> arquivo em ISO-8859-1 do STDIN e jogar para STDOUT em UTF-8, isso é canja de<br>
>> galinha. Sempre que abre um handle, é só especificar o que tem dentro que...<br>
>> Aí que está o MEU problema: nunca sei de antemão o que tem dentro :P<br>
>> A solução mais viável que encontrei até agora foi:<br>
>><br>
>> my $buf;<br>
>><br>
>><br>
>> eval {<br>
>> open(TXT, '<', $file) or die "impossivel abrir $file: $!";<br>
>><br>
>><br>
>> binmode TXT, ':bytes';<br>
>> local $/ = undef;<br>
>><br>
>><br>
>> $buf = <TXT>;<br>
>> close TXT;<br>
>><br>
>><br>
>> };<br>
>><br>
>> my $iconv = new Text::Iconv(detect_utf8($buf) ? 'utf-8' :<br>
>> 'iso-8859-1', 'utf-8');<br>
>><br>
>><br>
>> $buf = $iconv->convert($buf);<br>
>><br>
>><br>
>> Encode::_utf8_on($buf);<br>
>><br>
>> Explicando: abro o arquivo do jeito "cru", sem nenhuma codificação. Carrego<br>
>> o conteúdo no buffer. Aí uso Text::Iconv para converter a codificação.<br>
>> Detalhe importantíssimo: mesmo que os dados já estejam em UTF-8, ainda assim<br>
>> precisa aplicar o Text::Iconv. E ainda não acabou: Perl não reconhece o<br>
>> buffer como algo que tenha codificação UTF-8 até que eu force o flag UTF-8.<br>
>> Pronto! Depois disso tudo, $buf é um autêntico UTF-8. Posso dar uc() que "ã"<br>
>> vira "Ã", e /\w/ pega os acentos também.<br>
>> Aqui está o código completo: <a href="http://tinypaste.com/c3680" target="_blank">http://tinypaste.com/c3680</a><br>
>> A pergunta é: existe alguma maneira menos ineficiente de se fazer isto?<br>
>><br>
>> ABS()<br>
>><br>
>><br>
>> _______________________________________________<br>
>> SaoPaulo-pm mailing list<br>
>> <a href="mailto:SaoPaulo-pm@pm.org">SaoPaulo-pm@pm.org</a><br>
>> <a href="http://mail.pm.org/mailman/listinfo/saopaulo-pm" target="_blank">http://mail.pm.org/mailman/listinfo/saopaulo-pm</a><br>
>><br>
><br>
><br>
><br>
> --<br>
> "If you’ve never written anything thoughtful, then you’ve never had<br>
> any difficult, important, or interesting thoughts. That’s the secret:<br>
> people who don’t write, are people who don’t think."<br>
><br>
<br>
<br>
<br>
--<br>
"If you’ve never written anything thoughtful, then you’ve never had<br>
any difficult, important, or interesting thoughts. That’s the secret:<br>
people who don’t write, are people who don’t think."<br>
_______________________________________________<br>
SaoPaulo-pm mailing list<br>
<a href="mailto:SaoPaulo-pm@pm.org">SaoPaulo-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/saopaulo-pm" target="_blank">http://mail.pm.org/mailman/listinfo/saopaulo-pm</a><br>
</div></div></blockquote></div><br>