Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

help needed in encoding

by uva (Sexton)
on Mar 17, 2006 at 09:51 UTC ( [id://537416]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://537416]
Approved by bart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2025-01-22 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (63 votes). Check out past polls.