[Chapter 11] 11.7 The FileHandle Module
Author: Randal L. Schwartz, Erik Olson & Tom Christiansen
Date: 1999-07-02T01:35:01Z

#

| Chapter 11 Formats |

## 11.7 The FileHandle Module

Because Perl was designed to be a practical extraction and report language, formats were one of the earliest constructs incorporated into the language. As such, the format interface is starting to show its age, particularly when you have to resort to ugly variable names and esoteric `select` manipulations merely to switch the currently active format.

The FileHandle module provides a more intuitive approach to these matters. For example, here's the easy way to perform the same manipulations we demonstrated earlier in the section "Changing the Format Name."

    use FileHandle; # load library

    format_name REPORT "ADDRESSLABEL";
    write REPORT;

    format_name REPORT "SUMMARY";
    write REPORT;

This object-oriented module lets you treat filehandles as though they were objects.[5] All the filehandle-specific built-in punctuation variables have more mnemonic interfaces. See Chapter 2 of Programming Perl, or the perlform documentation, for the complete description of these.

> [5] See Chapter 18, CGI Programming, for more explanation about objects.

11.6 Changing Defaults for Formats |  | 11.8 Exercises