Perl Study Notes (v)--input and output

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.