in reply to Re: Perl mySQL and £ signs
in thread Perl mySQL and £ signs

I think what's happening is that the original string is a Unicode string, then it gets stored in MySQL and retrieved again.

What comes back is a utf-8 encoded string, but it's not marked as a Unicode string in perl.

What you need to do is help perl out by marking the string returned by DBI/mysql as a Unicode string:

use Encode qw(_utf8_on); _utf8_on($field_value_returned_by_dbi);

Replies are listed 'Best First'.
Re^3: Perl mySQL and £ signs
by graff (Chancellor) on Sep 19, 2005 at 16:39 UTC
    Good point -- thanks. Though I might prefer the "publicly supported" method for doing that "conversion" (turning on the utf8 flag) -- one that doesn't involve a function whose initial underscore in the name asserts that it is intended to be "private" within Encode.pm (hence subject to change in a later release):
    use Encode; ... my $utf8_string = decode( 'utf8', $field_value_from_db );
    Another point I should have considered earlier is that the OP might not want utf8 to be stored in the database (because of its "extra bulk"). If so, it would be better for the perl code that loads data into mysql to apply the appropriate encoding first (assuming the OP knows which non-unicode character set is suitable) -- e.g.:
    my $field_value_for_db = encode( 'iso-8859-1', $utf8_string );
    This way, nothing special needs to be done when pulling the data back out of the database for a non-utf8 display.