File Manipulation

The two most common things you will do with a file is open and close it. Closing a file is very simple and is discussed first. Opening a file depends on what you are going to do with the file, so a little extra time is spent explaining it.

The close Command

Closing a filehandle is not a necessary step up through version 5 of Perl. A file is automatically closed when the program ends or when a new file is opened with the same FILEHANDLE name. There is no guarantee that this will hold true in future versions of Perl, and it is also good programming etiquette to close any files that you open. If you do not remember what filehandles are, see the previous section that discusses them. The syntax is simple:

close FILEHANDLE;

I give ...

Get Practical UNIX 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.