Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Arabic Encodding Problem

by andal (Hermit)
on Feb 10, 2014 at 08:06 UTC ( [id://1074200]=note: print w/replies, xml ) Need Help??


in reply to Re: Arabic Encodding Problem
in thread Arabic Encodding Problem

This is very good point. From HTML::TreeBuilder documentation:

When you pass a filename to parse_file, HTML::Parser opens it in binary mode, which means it's interpreted as Latin-1 (ISO-8859-1). If the file is in another encoding, like UTF-8 or UTF-16, this will not do the right thing.

Replies are listed 'Best First'.
Re^3: Arabic Encodding Problem
by malak (Initiate) on Feb 10, 2014 at 09:01 UTC
    The point is some files managed well and can be presented as normal Arabic text. So I guess it is not the HTML::Parser problem. Any way do you recommend any solution to test?

      It was already recommended. Pass file handle instead of file name to HTML::TreeBuilder method. This should make sure that your input is interpreted as UTF-8. Then you have to make sure that your STDOUT is also reopened for using UTF-8 encoding.

      And of course, check what is actual encoding of your input files.

      You also should get good understanding on difference between "characters" and "octets". In few words, there is Unicode standard which assigns 4 octects (integer number) to each known "character" (image). Data files may use either these octects, or any other system. Files don't contain "characters", only octets. When perl reads files, it gets octets. Now, you want perl to work with "characters" corresponding to those octets. So you have to tell perl how to map octets to characters. For this, the "encoding" rule for file handles can be used. But you have to provide correct map. Now, after perl has worked with "characters" you want it to save results in file again. But for file you need "octets", not "characters". Again perl needs from you a map on how to convert characters to octets. That is why you should specify encoding for your STDOUT.

      The fact, that you get some of the files correctly does not mean anything. All depends on encoding of the text that you have there. Things may work for some cases even when they are generally wrong.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-03-28 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found