luckysummer has asked for the wisdom of the Perl Monks concerning the following question:

How can I set up footer at report end with format function?

http://www.perlmonks.com/?node=perlman%3Aperlform

It only tell us how to add header.

Please help answer.

#!/usr/bin/perl use strict; use warnings; my ($name,$login,$office,$uid,$gid, $home); open FD,"</etc/passwd" or die "$?"; while(<FD>){ ($name,$login,$office,$uid,$gid, $home) = split (":",$_); $^ = 'STDOUT_TOP'; $~ = 'STDOUT'; ###$ = 'STDOUT_BOTTOM'; (dont know how to work) $= = 20; write; } format STDOUT_TOP = @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "Page $%" Passwd File Name Login Office Uid Gid Home ------------------------------------------------------------------ . format STDOUT_BOTTOM = End of Page @< $% . format STDOUT = @<<<<<<<<<<<<<<<<<< @||||||| @<<<<<<@>>>> @>>>> @<<<<<<<<<<<<<<<<< $name, $login, $office,$uid,$gid, $home .

Replies are listed 'Best First'.
Re: format - set up footer(bottom)
by Athanasius (Archbishop) on Dec 28, 2016 at 02:39 UTC

    Hello luckysummer, and welcome to the Monastery!

    From perlform#Footers:

    While $FORMAT_TOP_NAME 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. It's on the TODO list.

    Here's one strategy: If you have a fixed-size footer, you can get footers by checking $FORMAT_LINES_LEFT before each write() and print the footer yourself if necessary.

    Here's another strategy: Open a pipe to yourself, using open(MYSELF, "|-") (see open) and always write() to MYSELF instead of STDOUT. Have your child process massage its STDIN to rearrange headers and footers however you like. Not very convenient, but doable.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Ok,I got it. Very thanks for your help.:)
Re: format - set up footer(bottom)
by Anonymous Monk on Dec 28, 2016 at 02:45 UTC
      Thanks for your help.It's useful.