Opening Files

To read or write files in Perl, you need to open a filehandle. Filehandles in Perl are yet another kind of variable. They act as convenient references (handles, if you will) between your program and the operating system about a particular file. They contain information about how the file was opened and how far along you are in reading (or writing) the file; they also contain user-definable attributes about how the file is to be read or written.

You're already familiar with one filehandle from earlier lessons: STDIN. This filehandle is given to you automatically by Perl when your program starts, and it's usually connected to the keyboard device (you'll learn more details about STDIN later). The format for filehandle names is the ...

Get Sams Teach Yourself Perl in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.