Picture Formats
Perl has a mechanism to help you generate simple reports of the kind
you often see coming out of your mainframe’s line printer. (What, you
don’t have one of those?) To facilitate this, Perl helps you code up your
output page close to how it will look when it’s printed. It can keep track
of things like how many lines are on a page, the current page number, when
to print page headers, and so on. Keywords are borrowed from FORTRAN:
format to declare and write to execute; see the relevant entries in
Chapter 27. Fortunately, the layout is much more legible,
more like the PRINT USING statement of
BASIC. Think of it as a poor man’s nroff(1). (If you
know nroff, that may not sound like a
recommendation.)
Formats, like packages and subroutines, are declared rather than
executed, so they may occur at any point in your program. (Usually it’s
best to keep them all together.) They have their own namespace apart from
all the other types in Perl. This means that if you have a function named
“Foo”, it is not the same thing as a
format named “Foo”. However, the
default name for the format associated with a given filehandle is the same
as the name of that filehandle. Thus, the default format for STDOUT is named “STDOUT”, and the default format for filehandle
TEMP is named “TEMP”. They just look the same. They
aren’t.
Output record formats are declared as follows:
format NAME = FORMLIST .
If NAME is omitted, format STDOUT is defined.
FORMLIST consists of a sequence of lines, each of which ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access