uva has asked for the wisdom of the Perl Monks concerning the following question:

dear monks,
use Encode qw(encode); use Win32::Codepage; my $w32encoding = Win32::Codepage::get_encoding(); # e.g. "cp936" my $encoding = $w32encoding ? Encode::resolve_alias($w32encoding) +: ''; print $encoding ? encode($string, $encoding) : $string;
the out put is :: Unknown encoding ''
it means cp936 is not present ,but ,if i used in the other program decoding with cp936 is working fine
why this is happening ? can you explain that one.
the program where i used cp936 is given below
use Encode; use Win32::Codepage; use strict; use diagnostics; my $encoding= Win32::Codepage::get_encoding(); my $str8=decode($encoding,"中国的网&#39029 +;");#$encoding has the value cp936; open OUT,">:utf8","D:\\output1.doc" or print "could not open"; print "\nIs ".encode("$encoding",$str8)." utf8 format : ",utf8::is +_utf8($str8),"\n\n"; print OUT $str8."\n"; close OUT;

Replies are listed 'Best First'.
Re: help needed in encoding
by borisz (Canon) on Mar 17, 2006 at 10:21 UTC
    Propably you exchanged the parameters of encode?
    print $encoding ? encode($encoding, $string) : $string;
    Boris
Re: help needed in encoding
by GrandFather (Saint) on Mar 17, 2006 at 10:36 UTC

    From Encoding docs: "$octets = encode(ENCODING, $string [, CHECK])". Your parameters are in the wrong order.


    DWIM is Perl's answer to Gödel
      Thanks for everyone ,
      now its working, previously i misordered the parameters.
Re: help needed in encoding
by borisz (Canon) on Mar 17, 2006 at 10:02 UTC
    Propably you need to install Encode::CN for cp936. But I only guess.
    $euc_cn = encode("euc-cn", $string);
    Boris