Perl FAQ 4.18: How can I set up a footer format to be used with write()?

Perl FAQ 4.18

How can I set up a footer format to be used with write()?

While the $^ variable contains the name of the current header format, there is no corresponding mechanism to automatically do the same thing for a footer. Not knowing how big a format is going to be until you evaluate it is one of the major problems.

If you have a fixed-size footer, you can get footers by checking for line left on page ($-) before each write, and printing the footer yourself if necessary.

Another strategy is to open a pipe to yourself, using open(KID, "|-") and always write()ing to the KID, who then postprocesses its STDIN to rearrange headers and footers however you like. Not very convenient, but doable.

See the perlform(1) man page for other tricks.


Other resources at this site: