Use Perl to create the implementation code of files with specified encoding format (such as UTF-8)

Time:2022-5-9

Thus, some characters (especially wide characters) cannot be displayed correctly, that is, they are no longer in UTF-8 format.

terms of settlement:
The encoding format is specified when opening the output file, so there will be no random code after opening the output file.

Normal default open output file:

Copy codeThe code is as follows:

open(OUTPUT,’>>output.txt’)||die”can not open the file: $!”;

 

Define a file with a specified encoding format (or create a file with a specified encoding format using Perl):

 

Copy codeThe code is as follows:

open OUTPUT, “>:encoding(utf-8)”, “output.txt”;
print OUTPUT $something;
close OUTPUT;