File handle
The file handle (filehandle) is the name of the application that represents the I/O connection between the Perl process and the outside world. is not the name of the file.
Open File Handle
Default file handles provided by Perl: STDIN, STDOUT, STDERR
Open CONFIG, ' Dino '; # Open the config file handle and point it to Dino Open CONFIG, ' <dino '; # Ibid., read-only open Open Bedrock, ' >fred '; # Open file handle bedrock and output to new file Fred Open LOG, ' >>logfile '; # Open File in Append mode
Specify how data is encoded
Open CONFIG, ' <:encoding (utf-8) ', ' Dino ';
Write data to a file with a specific encoding
Open Bedrock, ' >:encoding (utf-8$file _name;
Close file handle
Close Bedrock;
with die Handling Fatal Errors
1 if (! Open LOG , ">>",' logfile ') {2die "Cannot create logfile:$!"; # $! is a readable system error message 3 }
Using die will automatically append the Perl program name and line number after the error message, if you do not want to be able to add a newline character \ n Remove
Automatic detection of fatal errors
1 use Autodie;
with say to Output
The function is similar to the print function, but automatically adds a line break when each line of content
Perl Study Notes (v)--input and output