Perl File Handling

What is File Handling in Perl programming?


File Handling is a method to read or write to a file or from a file. Perl uses a scripts memory known as "FILE HANDLE" where the contents is stored when a file is read or written to a file. File Handling is very useful for smaller projects, like web projects where large databases are not needed.

There are some predefined file handles in Perl they are STDIN, STDOUT, STDERR. STDIN is used to get the standard input, STDOUT used to get standard output, STDERR to get standard error messages. Advantage of using file handle is that user can store the changes in the handles, then decide whether to read or write or to display errors later.

Example :

open(DATA, "Filename");

In the above example "DATA" is the file handle, used for the specified "Filename", which the user can make use to store all changes. Usually the file handles are written in capital letters.

Ask Questions

Ask Question