And why isn’t the JSON data enough? JSON has a pretty option, which would pretty-print the data for you, not requiring you to (ab)use Dumper.
Keep in mind, that any JSON data generated by JSON is a byte stream and not a (Unicode) string.
- To print it in a terminal you should decode it into a string and tell Perl your terminal is UTF-8, as suggested above. Sending byte streams to terminals is a bad thing, definitely don’t do that.
- To print it into a file,
- you might be best off with a file that you opened as a binary (open my $FH, '>:raw', "myfilename.txt"). Any byte thrown at a raw file will appear there as intended.
- Or of course, you can decode it into a string, print it into the file, Perl will know that it’s a string and either figure out the byte stream format (aka. encoding) for the file, or you should be specifying one, eg. '>:encoding(UTF-8)'. Letting Perl do it for you is not necessarily a good idea :)
Yes, fully aware it looks extremely complicated :)