SoFunction
Updated on 2025-04-07

Use Perl to create implementation code for a file with a specified encoding format (such as utf-8)

This makes some characters (especially wide characters) unable to be displayed correctly, that is, they are no longer in the utf-8 format.

Solution:
When opening the output file, the encoding format is specified, and there will be no garbled code after opening the output file.

Normal default open output file:

Copy the codeThe code is as follows:

open(OUTPUT,'>>')||die"can not open the file: $!";

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

Copy the codeThe code is as follows:

open OUTPUT, ">:encoding(utf-8)", "";
print OUTPUT $something;
close OUTPUT;