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.