Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^3: Arabic Encodding Problem

by malak (Initiate)
on Feb 10, 2014 at 09:01 UTC ( #1074210=note: print w/replies, xml ) Need Help??

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

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?

Replies are listed 'Best First'.
Re^4: Arabic Encodding Problem
by moritz (Cardinal) on Feb 10, 2014 at 11:54 UTC
Re^4: Arabic Encodding Problem
by andal (Hermit) on Feb 10, 2014 at 12:35 UTC

    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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1074210]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2017-03-29 23:07 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (353 votes). Check out past polls.