in reply to Is there some universal Unicode+UTF8 switch?
Try utf8::all. It's not universal, because it handles only the core functionality, not libraries.
Your use case can be much simplified, though. I strongly suspect you have too much code. Consider:
- HTTP::Response provides both content (returns octets) and decoded_content (returns characters, appropriately decoded from Content-Type header).
- decode_json wants to consume octets.
Your CGI script's templating system should take care to produce UTF-8 encoded octets. If you don't have one, then either one ofuse LWP::UserAgent qw(); use JSON::MaybeXS qw(decode_json); my $ua = LWP::UserAgent->new; my $res = $ua->get('https://ru.wikipedia.org/w/api.php?action=query&fo +rmat=json&formatversion=2&list=allusers&auactiveusers&aufrom=%D0%91') +; die $res->status_line unless $res->is_success; my $json_OCTETS = $res->content; my $all_users_CHARACTERS = decode_json $json_OCTETS; my $continue_aufrom_CHARACTERS = $all_users_CHARACTERS->{continue}{auf +rom};
- use Encode qw(encode); my $continue_aufrom_OCTETS = encode('UTF-8', $continue_aufrom_CHARACTE +RS, Encode::FB_CROAK); STDOUT->print($continue_aufrom_OCTETS);
- binmode STDOUT, ':encoding(UTF-8)'; STDOUT->print($continue_aufrom_CHARACTERS);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Is there some universal Unicode+UTF8 switch?
by VK (Novice) on Sep 01, 2019 at 19:39 UTC | |
by daxim (Curate) on Sep 02, 2019 at 10:09 UTC | |
Re^2: Is there some universal Unicode+UTF8 switch?
by Anonymous Monk on Sep 02, 2019 at 11:29 UTC |
In Section
Seekers of Perl Wisdom