Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: NCR & CER to UTF-8

by theorbtwo (Prior)
on Nov 01, 2005 at 15:58 UTC ( [id://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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://504619]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-18 02:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found