On Thu, Dec 11, 2003 at 01:03:47PM +0200, Dana Sharvit - M wrote:
> what I dont understand is two things:
> 1.why do I need to read the string using IO ( open my $in1,
> "<:encoding(utf8)", \$str;)
> 2.why do I need to use the encode function before the from_to
> function($octet = encode("utf8", $_);)

The canonical code to do this is:

    use strict;
    use Encode;
    my $file = shift;
    open my $in, '<:utf8', $file or die $!;
    while (my $str = <$in>) {
        chomp($str);
        my $octet = encode( big5 => $str );
        print "$octet\n";
    }
    close $in;

Your original code used two variables, $str and $octet,
with no assignments between them.  Time to "use strict".

Thanks,
/Autrijus/

Reply via email to