programming-examples/perl/Report/Understanding Formats.pl

27 lines
914 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
A format defines how data will appear.
The format command defines a format.
The basic syntax follows:
format NAME = formatdata
The format definition ends with a single period on its own on a line.
The format data come in pairs of lines.
In each pair, the first line, called the picture line, lists how the data will look;
the second line, called the argument line, lists the global Perl variables that will hold the data.
When the report is generated, the data values get plugged into the picture lines.
For example,
format NAMES=
Last name : @<<<<<<<<<<<<<<<<<<<<
$lastname
First name: @<<<<<<<<<<<
$firstname
.
The @<<<<<<<<<<< format defines a left-justified data field.
The number of < characters defines how many spaces are allotted for the field. The lines with variables, $lastname and $firstname, aren't printed.
Only the lines that define the format are printed.