O'Reilly logo

Perl Pocket Reference, 5th Edition by Johan Vromans

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required