[Cascavel-pm] Problemas com "read" quando lendo caracteres UTF8

Daniel de Oliveira Mantovani daniel.oliveira.mantovani em gmail.com
Terça Agosto 24 15:12:09 PDT 2010


Quer dizer, http://mail.pm.org/pipermail/saopaulo-pm/2010/010691.html

Boa leitura.


2010/8/24 Daniel de Oliveira Mantovani <daniel.oliveira.mantovani em gmail.com>:
> Coloque, isso no começo do seu programa,
>
> use utf8;
>
> 2010/8/24 Ednardo Lobo <ednardo em lobo.eti.br>:
>> Gabriel,
>>
>> Alterando a codificação da entrada (STDIN) e da saída (STDOUT) o caractere
>> foi lido e impresso corretamente. Entretanto, operações como "eq" e "=~"
>> aplicadas a caracteres especiais falhou, veja:
>>
>> ---------------------------
>> binmode(STDIN,":utf8");
>> binmode(STDOUT,":utf8");
>>
>> my $x;
>>
>> read STDIN, $x, 1;
>>
>> if ($x =~ /^[cçaáº]/) {
>>    print "ok 1\n";
>> }
>>
>> if ($x eq 'ç') {
>>    print "ok 2\n";
>> }
>>
>> print "$x\n";
>> ---------------------------
>>
>>
>> Grato,
>>
>> Gabriel Vieira escreveu:
>>>
>>> 2010/8/24 Ednardo Lobo <ednardo em lobo.eti.br>:
>>>>
>>>> Estou com problemas para ler caracteres especiais de arquivos com a
>>>> codificação Unicode (UTF-8).
>>>>
>>>> Experimentem esse código:
>>>>
>>>> my $x;
>>>>
>>>> read STDIN,$x,1;
>>>>
>>>> print $x;
>>>>
>>>>
>>>> Caracteres especiais como "á", "ç" e "º" não serão lidos corretamente.
>>>>
>>>>
>>>> Tentei as seguintes soluções mas não surtiram efeito:
>>>>
>>>> 1) use open ':encoding(utf8)';
>>>>
>>>> 2) binmode(STDIN,':utf8');
>>>>
>>>>
>>>> Alguma sugestão?
>>>
>>> Você alterou a encode da entrada e conferiu com a saída, que não teve
>>> a encode alterada
>>>
>>> Teste:
>>> ---------------8<---------------
>>> binmode(STDIN,":utf8");
>>> binmode(STDOUT,":utf8");
>>> my $x;
>>> read STDIN, $x, 1;
>>> print$x;
>>> --------------->8---------------
>>
>>
>> --
>>    Ednardo Lobo
>>
>>    www.lobo.eti.br
>> _______________________________________________
>> Cascavel-pm mailing list
>> Cascavel-pm em pm.org
>> http://mail.pm.org/mailman/listinfo/cascavel-pm
>>
>
>
>
> --
> http://www.danielmantovani.com
>
> "If you’ve never written anything thoughtful, then you’ve never had
> any difficult, important, or interesting thoughts. That’s the secret:
> people who don’t write, are people who don’t think."
>



-- 
http://www.danielmantovani.com

"If you’ve never written anything thoughtful, then you’ve never had
any difficult, important, or interesting thoughts. That’s the secret:
people who don’t write, are people who don’t think."


Mais detalhes sobre a lista de discussão Cascavel-pm