[Israel.pm] Can't use Hebrew with perl on mysql 4.1

Mikhael Goikhman migo at homemail.com
Tue Sep 27 11:47:36 PDT 2005


On 27 Sep 2005 18:58:59 +0300, Issac Goldstand wrote:
> 
> I was going to point out that Perl 5.8 keeps it strings in Unicode
> (utf8, I believe).  To use this with MySQL, simply use utf8_general.  To
> convert from ISO-8859-8 to utf8, try doing something like :
> 
> use Encode
> 
> open IN "iso-8859-8"
> open OUT ">utf8"
> 
> while (<IN>) {print OUT $_};

This syntax is not quite correct. Here is a working syntax (taken from
Encode manual page):

	open my $in,  "<:encoding(iso-8859-8)", $infile  or die;
	open my $out, ">:encoding(utf8)",       $outfile or die;
	while (<$in>) { print $out $_; }

The magic is done by PerlIO itself, so no need in Encode module here.
There is another way, using Encode function from_to:

	open my $in,  "<", $infile  or die;
	open my $out, ">", $outfile or die;
	while (<$in>) {
		from_to($_, "iso-8859-8", "utf8", 1);
		print $out $_;
	}

But IMHO it is easier to convert files from unix:

	iconv -f iso-8859-8 -t utf8 <input.txt >output.txt

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list