Formats

formline picture, list

Formats list according to picture and accumulates the result into $^A.

write [ filehandle ]

Writes a formatted record to the specified file, using the format associated with that file. If filehandle is omitted, the currently selected one is taken.

Formats are defined as follows:

  • format [ name ] =

  • formlist

  • .

formlist is a sequence of lines, each of which is either a comment line (# in the first column), a picture line, or an argument line. A picture line contains descriptions of fields. It can also contain other text that will be output as given. Argument lines contain lists of values that are output in the format and order of the preceding picture line.

name defaults to STDOUT if omitted.

To associate a format with the current output stream, assign its name to the special variable $~. A format to handle page breaks can be assigned to $^. To force a page break on the next write, set $- to zero.

Picture fields are:

@<<<

Left-adjusted field. Repeat the < to denote the desired width.

@>>>

Right-adjusted field.

@|||

Centered field.

@##.##

Numeric format with implied decimal point.

@0#.##

Same, padded with leading zeros if necessary.

@*

Multiline field.

Use ^ instead of @ for multiline block filling.

Use ~ in a picture line to suppress unwanted empty lines.

Use ~~ in a picture line to have this format line repeated until it would yield a completely blank line. Use with ^ fields to have them repeated until exhausted.

See also $^, $~, $^A, $%, $:, $^L, $-, and $= in the section Special ...

Get Perl Pocket Reference, 5th Edition 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.