1/10/2018 - 11:41 AM

Specify encodings with filehandles

If you know that your input file is UTF-8, you can specify that by putting a colon after the file mode and naming the encoding.

open CONFIG, '<:encoding(UTF-8)', 'dino';

# if you want to write your data to a file with a particular encoding, same thing but using one of the write modules:
open BEDROCK, '>:encoding(UTF-8)', $file_name;
open LOG, '>>:encoding(UTF-8)', $logfile_name();

# Using encoding(), you can specify other encodings too. 
# Use this to get a list of all the encodings that your perl understands:
$ perl -MEncode -le "print for Encode->encodings(':all')"
# You should be able to use any of the names from that list as an encoding for reading or writing a file.