Learning Perl on Win32 Systems

Learning Perl on Win32 SystemsSearch this book
Previous: 10.8 ExercisesChapter 11Next: 11.2 Defining a Format
 

11. Formats

Contents:
What Is a Format?
Defining a Format
Invoking a Format
More About the Fieldholders
The Top-of-Page Format
Changing Defaults for Formats
The FileHandle Module
Exercises

11.1 What Is a Format?

Perl stands, among other things, for "Practical Extraction and Report Language." It's time to learn about that "...report language" business.

Perl provides a simple report-writing template, called a format. A format defines a constant part (the column headers, labels, fixed text, or whatever) and a variable part (the current data you're reporting). The shape of the format is very close to the shape of the output, as with formatted output in COBOL or the print using clauses of some BASICs.

Using a format consists of doing three things:

  1. Defining a format

  2. Loading up the data to be printed into the variable portions of the format (fields)

  3. Invoking the format

Most often, the first step is done once (in the program text so that it gets defined at compile time[1]), and the other two steps are performed repeatedly.

[1] You can also create formats at runtime using the eval function, as described in Programming Perl and perlform.


Previous: 10.8 ExercisesLearning Perl on Win32 SystemsNext: 11.2 Defining a Format
10.8 ExercisesBook Index11.2 Defining a Format