Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Encode::decode issue with string

by Anonymous Monk
on Jul 23, 2019 at 18:18 UTC ( [id://11103243]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks
why Encode::decode is working for one string and not for other.
Like it is decoding string with Japanese characters well but not decoding string with Chinese and Spanish characters.
Please help.

Replies are listed 'Best First'.
Re: Encode::decode issue with string
by choroba (Cardinal) on Jul 23, 2019 at 21:44 UTC
    It works for me.
    #!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use Encode qw{ decode }; my %utf8 = ( japanese => "\xe6\x84\x9b", chinese => "\xe5\x92\x8c\xe5\xb9\xb3", spanish => "\x61\x6c\x65\x67\x72\xc3\xad\x61"); binmode STDOUT, ':encoding(UTF-8)'; for my $language (keys %utf8) { my $decoded = decode('UTF-8', $utf8{$language}); say join ', ', $language, length $decoded, $decoded; }

    Output (on a UTF-8 terminal):

    chinese, 2, 和平
    japanese, 1, 愛
    spanish, 7, alegrķa
    
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: Encode::decode issue with string
by Laurent_R (Canon) on Jul 23, 2019 at 18:37 UTC
    Please provide example code showing the behavior you're describing.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-20 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found