Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

EncodingConversion in perl

by vkca (Initiate)
on Dec 20, 2009 at 16:09 UTC ( [id://813637]=perlquestion: print w/replies, xml ) Need Help??

vkca has asked for the wisdom of the Perl Monks concerning the following question:

I have installed Oracle 9i database with UTF8 encoding scheme. There is a word which i have to save it in database.(The word i'm saving is Ïntêrnatïônàlîzâtion). If i save as Ïntêrnatïônàlîzâtion, it is saving some junk characters. So i want a perl script that saves the word Ïntêrnatïônàlîzâtion as Internationalization in the database and when retreiving from database, i want it as Ïntêrnatïônàlîzâtion. Cau you help me in writing a perl sciript that does this conversion..

Replies are listed 'Best First'.
Re: EncodingConversion in perl
by afoken (Chancellor) on Dec 20, 2009 at 16:55 UTC

    Read the Unicode chapter in the DBD::Oracle documentation, it explains exactly what has to be done to read and write Oracle Data as UTF-8. Make sure that other I/O from and to perl is also UTF-8, so your strings contain unicode characters (utf8 flag on) and not bytes representing a random unicode encoding (utf8 flag off). See also the tests t/40UnicodeRoundTrip.t and t/41Unicode.t in DBD::ODBC for some basic examples.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: EncodingConversion in perl
by Corion (Patriarch) on Dec 20, 2009 at 16:50 UTC

    How would your hypothetical script know to convert Internationalization back to Ïntêrnatïônàlîzâtion instead of Internätiönälizätiön?

    If you want to save your data as Unicode data, you'll have to look at how your database driver (likely DBD::Oracle) stores character data in a character set encoding. You will also have to make your whole processing pipeline from input to storage and back to output respect that encoding. If you want to use ASCII-encoded data to search for your other encoded data, you will have to add a second column to your data table in which you store the asciification.

Re: EncodingConversion in perl
by graff (Chancellor) on Dec 21, 2009 at 05:43 UTC
    To supplement the excellent advice given above, I'd like to add that you should take care to know your display tools really well, to make sure that valid utf8 data is displayed correctly. This involves whatever text editor, terminal window, browser or other display method you use to check your data. It can also be a good idea to have two or more independent ways to look at the contents of the database.

    It will help to have tools that allow you to view utf8 text data in a more detailed, explicit manner -- for example (shameless plug), I posted a couple command-line scripts that can help for both confirming valid utf8 data and diagnosing faulty data: tlu -- TransLiterate Unicode, and unichist -- count/summarize characters in data. They might help you in figuring out a suitable idiom for handling your text data in a way that avoids corruption.

Re: EncodingConversion in perl
by wazoox (Prior) on Dec 21, 2009 at 12:43 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (None)
    As of 2024-04-25 01:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found