CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
utf8

 



al3ss
New User

Sep 24, 2008, 9:04 AM

Post #1 of 4 (2178 views)
utf8 Can't Post

Hi all, the question is plain simple, I've been trying to fix this for a while but... Please help me.
I am using UTF-8 encoded .pl files, I have


Code
use strict; 
use utf8;
use encoding 'utf8';


On top of all my .pl files, now somewhere I do:


Code
print "title = ", ${$lot}{title}, " = ${$lot}{title} \n";


Which prints:


Code
title = Attribué à Jacob de HEUSCH = Attribu� � Jacob de HEUSCH


This output is screenshot in the attached PNG.

I could solve this by always printing variables directly, but this also happens when I use those variables with DBI, and these values get truncated when saved in my database. I am calling SET NAMES utf8 when creating the DB connection.

Any solution? Thanks in advance,

Al3ss
Attachments: Picture 3.png (7.90 KB)


shawnhcorey
Enthusiast


Sep 24, 2008, 9:15 AM

Post #2 of 4 (2176 views)
Re: [al3ss] utf8 [In reply to] Can't Post


In Reply To
Hi all, the question is plain simple, I've been trying to fix this for a while but... Please help me.
I am using UTF-8 encoded .pl files, I have


Code
use strict; 
use utf8;
use encoding 'utf8';


On top of all my .pl files, now somewhere I do:


Code
print "title = ", ${$lot}{title}, " = ${$lot}{title} \n";


Which prints:


Code
title = Attribué à Jacob de HEUSCH = Attribu� � Jacob de HEUSCH


This output is screenshot in the attached PNG.

I could solve this by always printing variables directly, but this also happens when I use those variables with DBI, and these values get truncated when saved in my database. I am calling SET NAMES utf8 when creating the DB connection.

Any solution? Thanks in advance,

Al3ss


`use utf8;` allows you to use UTF-8 enocding directly in your Perl script. It does so by converting into an internal representation. You have to convert back to UTF-8 to print it.

Try:

Code
binmode STDOUT, ':utf8'; 
print "title = ", ${$lot}{title}, " = ${$lot}{title} \n";


See `perldoc -f binmode` for details.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


al3ss
New User

Sep 25, 2008, 3:14 AM

Post #3 of 4 (2167 views)
Re: [shawnhcorey] utf8 [In reply to] Can't Post

Thanks for your reply. Sadly, your suggestion hasn't changed anything - the output is still the same, and even if it had worked, I don't think it'd have helped on the DBI side.

Any other suggestion?

Al3ss


shawnhcorey
Enthusiast


Sep 27, 2008, 6:48 AM

Post #4 of 4 (2083 views)
Re: [al3ss] utf8 [In reply to] Can't Post


In Reply To
Thanks for your reply. Sadly, your suggestion hasn't changed anything - the output is still the same, and even if it had worked, I don't think it'd have helped on the DBI side.

Any other suggestion?

Al3ss


Are you using symbolic references? (See `perldoc perlref` for details). Symbolic references can do weird things inside quotes.

And, if memory serves, the entity � means an invalid UTF-8 character has been encountered and this symbol replaced it.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives