Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Text File to MySQL: Encoding

by ppremkumar (Novice)
on Jul 05, 2013 at 10:27 UTC ( #1042674=perlquestion: print w/ replies, xml ) Need Help??
ppremkumar has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Team

I am back again for my next question.

  1. OS: Windows 7 Professional 32-bit (6.1, Build 7601) Service Pack 1 (7601.win7sp1_gdr.130318-1533)
  2. Perl: perl 5, version 16, subversion 3 (v5.16.3)

I am trying to read line by line a text file with special characters and store each line in MySQL server, whose character set settings are shown below.

Variable Value
character_set_client $utf8
character_set_database $utf8
character_set_filesystem $binary
character_set_results $utf8
character_set_server $utf8
character_set_system $utf8

The charset of both the schema and the table is set as utf8.

Input Text File Line

Aderŋľŀīửừứ, R., & Kelley, K. W. (2007). A global view of twenty years of Brain, Behavior, and Immunity. Brain, Behavior, and Immunity, 21, 2022

Corresponding Entry in MySQL

Aderñŋšžľŀīửừứ, R., & Kelley, K. W. (2007). A global view of twenty years of Brain, Behavior, and Immunity. Brain, Behavior, and Immunity, 21, 20–22.

My code to read the text file includes: open $REF_INPUT_FH, '<:encoding(UTF-8)',  $filepath . $job_number. '_BIB.txt';

I read each line and insert data:

$dbh->do("INSERT INTO es_ce_automation_bibliography_linking.`$job_chos +en` (bib_book_element, bib_ID, bib_item, bib_added_by, bib_added_date +) VALUES( '$book_element', '$temp_ID', '$temp_RefItem', '$created_by', now() )") or warn 'Some error!'

What am I doing wrong?

Thanks,

Prem

Comment on Text File to MySQL: Encoding
Select or Download Code
Re: Text File to MySQL: Encoding
by moritz (Cardinal) on Jul 05, 2013 at 10:43 UTC

      Thank you, @moritz.

      It worked.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2015-07-03 11:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (51 votes), past polls