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

I have a Perl format that doesn't want to print the top of the report.

open EOS_REPORT, "| lp -d lex_text" or die "Cannot open EOS report for + printing: $!"; # lots of code to assemble data write EOS_REPORT; close EOS_REPORT; format EOS_REPORT_TOP = @>>>>>>>>>>>>>>>>>>> 'Page: ' . $% @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| "End of day register report" @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| $today Run by: @<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>>>>>>>>>>>>>>>> $name, "Terminal: ".$hostname . format EOS_REPORT = Total Sales --------------- @>>>>>>>>>>>>>> $total Total Cash Total Account Total Check --------------- --------------- --------------- @>>>>>>>>>>>>>> @>>>>>>>>>>>>>> @>>>>>>>>>>>>>> $tcash, $taccount, $tcheck CC Manual Auth Total Credit --------------- --------------- @>>>>>>>>>>>>>> @>>>>>>>>>>>>>> $tcc_man_auth, $tcredit @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| "Price Overrides" @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| "(Negative quantities are overrides on refunds)" Clerk SKU Old price New price ------------------- -------------------- ---------- ---------- ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~ $override_report .

I can't find anything that I've changed, but the top of the report used to print and now it doesn't. I don't know formats terribly well, so I don't know what to look for. I haven't found any references anywhere which indicate what the problem might be.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
•Re: Top of format won't print
by merlyn (Sage) on Jul 09, 2002 at 18:31 UTC

      I didn't know that, but I'm skeptical -- which confuses me, considering the source. The actual "top of report" from yesterday (formatted to fit the text window - along with the beginning of the main body of the report):

      Page: 1 End of day register report Mon Jul 8 18:10:38 2002 Run by: Ovid Terminal: some.terminal Total Sales --------------- 12.34

      I just typed that in directly from a test report sitting by my right hand.

      From perldoc -f write (emphasis mine):

      Top of form processing is handled automatically: if there is insufficient room on the current page for the formatted record, the page is advanced by writing a form feed, a special top-of-page format is used to format the new page header, and then the record is written. By default the top-of-page format is the name of the filehandle with "_TOP" appended, but it may be dynamically set to the format of your choice by assigning the name to the "$^" variable while the filehandle is selected. The number of lines remaining on the current page is in variable "$-", which can be set to "0" to force a new page.

      And from page 123 of the 2nd Camel (emphasis mine):

      Top-of-form processing is by default handled by a format with the same name as the current filehandle with "_TOP" concatenated to it. It's triggered at the to of each page.

      So, perldoc mentions something about a "special top-of-page format" used to format new page headers, but this seems very unclear. What "special" format. How does this differ from the current "top-of-page" format? This program used to do what I want and now it doesn't. I've also heard that our client has had intermittant problems with this. Seems like a bug, but whether it's in my code or Perl, I don't know. I suspect a bug in the documentation, actually :) I'd be happy to submit a doc patch to P5P, if I knew what I was patching (if, in fact, unclear docs are the problem).

      Cheers,
      Ovid

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Top of format won't print
by RMGir (Prior) on Jul 09, 2002 at 20:54 UTC
    For what little it's worth, this code prints the _TOP format on every page (including the first), with 3 different perls. perl 5.6.1 for cygwin, ActivePerl 633 (also a 5.6.1), and perl 5.6.0 on Linux.

    I don't have a 5.8.0 RC installed, though; maybe that's the problem?

    Here's the code:

    #!/usr/bin/perl -w use strict; my $total; format STDOUT_TOP = @>>>>>>>>>>>>>> 'Page: ' . $% Numbers --------------- . format STDOUT = @>>>>>>>>>>>>>> $total . for $total(1..200) { write STDOUT; }
    (Edit: Just ran a grepmail on my copy of the p5p archives, and the only thing even remotely related to this appears to be bug 20020227.005, and that's a problem with empty _TOP sections... I don't see any sign that this behaviour changed from 5.6.1 to 5.8.0)
    --
    Mike