use open ':std', ':encoding(UTF-8)';
####
use open ':std', ':encoding(UTF-8)';
##
##
use utf8;
use encoding ':std', ':encoding(UTF-8)';
use JSON::XS qw( decode_json encode_json );
my $s = "Queensr˙che";
printf("U+%v04X %s\n", $s, $s);
{
# Uses encoding specified by "use open".
open(my $fh, '>', 'foo.txt') or die $!;
print($fh "$s\n");
}
{
# Uses encoding specified by "use open".
open(my $fh, '<', 'foo.txt') or die $!;
chomp( my $got = <$fh> );
printf("U+%v04X %s\n", $got, $got);
}
{
# :raw overrides default encoding specified above
# since encode_json already encodes using UTF-8
open(my $fh, '>:raw', 'foo.json') or die $!;
print($fh encode_json( { text => $s } ));
}
{
my $json = do {
# Similarly, decode_json expects UTF-8.
open(my $fh, '<:raw', 'foo.json') or die $!;
local $/;
<$fh>
};
my $got = decode_json($json)->{text};
printf("U+%v04X %s\n", $got, $got);
}