Chapter 10. Getting a Handle on Files

Getting a Handle on Files

The User-Defined Filehandle

If you are processing text, you will regularly be opening, closing, reading from, and writing to files. In Perl, we use filehandles to get access to system files.

A filehandle is a name for a file, device, pipe, or socket. In Chapter 4, “Getting a Handle on Printing,” we discussed the three default filehandles, STDIN, STDOUT, and STDERR. Perl allows you to create your own filehandles for input and output operations on files, devices, pipes, or sockets. A filehandle allows you to associate the filehandle name with a system file[1] and to use that filehandle to access the file.

Opening ...

Get Perl by Example, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.