[SP-pm] Problemas com Hexadecimal

Adriano Ferreira aferreira at shopzilla.com
Thu Aug 14 17:00:38 PDT 2008


On Thu, Aug 14, 2008 at 8:32 PM, Otávio Fernandes <otaviof at gmail.com> wrote:
> Senhores,
>
> Estou com algumas dúvidas sobre decodificação hexadecimal. Vejam:
>
>  1 #!/usr/bin/env perl
>  2
>  3 use strict;
>  4 use warnings;
>  5
>  6 use Encode;
>  7
>  8 open( my $BODY,
>  9     '/home2/otavio.fernandes/users/teste/cur/1217853567.20253.shike,S=34403:2,S'
>  10 ) or die $!;
>  11
>  12 while (<$BODY>) {
>  13     chomp;
>  14     if (/forwarding the table/) {
>  15         print "Debug -> antes  #", $_, "#\n";
>  16         s/&#([0-9a-f]+);/chr(hex($1))/ige;
>  17         print "Debug -> encode #", encode( "utf8", $_ ), "#\n";
>  18         print "Debug -> depois #", $_, "#\n";
>  19     }
>  20 }
>  21
>  22 close($BODY);
>  23
>  24 __END__
>
> E o resultado é:
>
> Debug -> antes  #prohibited. However I&#8217;m forwarding the table
> that&#8217;s contents =#
> Debug -> encode #prohibited. However Ièm forwarding the table thatès contents =#
> Wide character in print at decode_qp.pl line 18, <$BODY> line 844.
> Debug -> depois #prohibited. However Ièm forwarding the table thatès contents =#

Se você quer decodificar textos com "HTML entities" como:

          I&#8217;m

você deve usar

         use HTML::Entities qw( decode_entities );
         my $encoded_s = "I&#8217;m";
         my $s = decode_entities( $encoded_s ); # conterá "I'm"

Depois disso, o string está na representação interna do Perl (que se
for necessário, é UTF-8).

E note que no &#8217;  o 8217 não é hexadecimal, é decimal mesmo.



> Como eu faço para que os caracteres sejam decodificados para UTF8?
>
> Ainda não consegui perceber onde eu estou errando.
>
> um abraço,
>
> --
>  | --
>  | Otávio Fernandes <otaviof at gmail dot com>
>  | --
> _______________________________________________
> SaoPaulo-pm mailing list
> SaoPaulo-pm at pm.org
> http://mail.pm.org/mailman/listinfo/saopaulo-pm
>


More information about the SaoPaulo-pm mailing list