Skip to Main Content
Perl Pocket Reference, 5th Edition
book

Perl Pocket Reference, 5th Edition

by Johan Vromans
July 2011
Intermediate to advanced content levelIntermediate to advanced
104 pages
2h 14m
English
O'Reilly Media, Inc.
Content preview from Perl Pocket Reference, 5th Edition

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

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.
Start your free trial

You might also like

Perl Testing: A Developer's Notebook

Perl Testing: A Developer's Notebook

Ian Langworth, Chromatic
Perl Hacks

Perl Hacks

Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe

Publisher Resources

ISBN: 9781449311186Errata Page