Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^3: NCR & CER to UTF-8

by theorbtwo (Prior)
on Nov 01, 2005 at 15:58 UTC ( #504619=note: print w/replies, xml ) Need Help??

in reply to Re^2: NCR & CER to UTF-8
in thread NCR & CER to UTF-8

1) When you use perl with data that isn't ASCII, it's generally a good idea to tell perl what encoding you expect the filehandles to use, by using binmode: binmode(\*STDOUT, ':utf8');. By default, even in utf8 locales, STDIN, STDOUT, and STDERR are assumed to be latin-1. If you had a use warnings, you would have gotten a lot of warnings about a wide character in print -- one for every character that wasn't in latin-1.

2) From that screenshot, it appears that what you have is mostly valid utf8, but the thing you are using to view it expects it to be latin-1, not utf8.

3) It's dangerous to HTML-unescape text containing unescaped HTML or XML tags; after doing so it is impossible to tell the difference between what was <foo> and &lt;foo&gt;, making tags out of things that were not tags before.

4) Why aren't you using a HTML parser, such as HTML::TreeBuilder?

Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Replies are listed 'Best First'.
Re^4: NCR & CER to UTF-8
by vnpenguin (Beadle) on Nov 01, 2005 at 16:14 UTC

    Hi theorbtwo,

    Thank you so much for your quick reply.

    1) By using binmode, I got correct UTF-8 output now.

    2),3) & 4) You are absolutely right. I need learn more and more about Perl :)

    Thank you for all help.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://504619]
[Corion]: ambrus: AnyEvent(::HTTP) doesn't integrate well with Prima, that's my main problem
[Corion]: There is a weirdo shim because there is a POE integration for Prima, and if you use that, you can use the POE adapter of AnyEvent. What I'd want is something transport agnostic that parses HTTP or produces HTTP output, so that the communication with ...
[Corion]: ... the socket is done by my code. Ideally that module would not be based on callbacks ;)
[Corion]: Basically, something that decouples the HTTP parsing (+ determining whether to redirect, etc) from the IO
[Corion]: All clients I'm aware of don't do that but issue all IO themselves

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2016-12-07 15:50 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (130 votes). Check out past polls.