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

Hello all, I've a question for you to ponder. I have recently written a script to rip through a log file, pick out interesting tidbits, and display them in a report, depending on what type of tidit it is. I have all of my reports being called in subroutines, and call them all in succession. My problem is that in the final report, there is a "^L" at the beginning of each report. Is there something that I am doing incorrectly? Here is a sample of one of my subroutines (they are all the same, except for the header and the data they use)
sub DepOverrideRpt { my ($i,$temp); format DepOverride_Hdr= Dependencies Overriden ======================= Job | Time -------------|--------- . my($key, $job, $time); format DepOverride= @<<<<<<<<<<<<|@>>>>>>>> $job,$time . $temp=select(OUTFILE); $~="DepOverride"; $^="DepOverride_Hdr"; $-=0; select($temp); foreach $i (0 .. 1) { foreach $key (sort {$o_override[$i]{$a} cmp $o_override[$i]{$b} } key +s %{$o_override[$i]}) { $job=$key; $time=$o_override[$i]{$key}; write OUTFILE; } } print OUTFILE "=======================\n\n"; }
In the above example @o_override is an array of hashes used to store data from different days (%o_override[0] is a hash containing data from 6am - midnight on day 1, %o_override contains data from midnight to 6am on day 2) Any help would be appreciated, thor

Replies are listed 'Best First'.
Re: Control Characters in reports...
by McD (Chaplain) on Feb 23, 2001 at 02:08 UTC
    thor writes:

    My problem is that in the final report, there is a "^L" at the beginning of each report.

    Yup. That's a "Form feed" - you get 'em for free with write. According to Programming Perl (2nd Ed),

    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,

    When you set $- to zero, you're forcing a new "page", and hence ^L, on every write. Tinkering with that and $= ought to let you get rid of the ^L problem.

    Peace,
    -McD

      Thanks for the info. Now the problem is getting everything to print out. It seems that if I set $- to anything but zero, the header won't print, but everything else prints without the form feed. My question now is: how is $- used? The way that I am thinking of it is every write that is performed, perl checks against $- and determines whether it can get that line on the current page or not. Am I correct in this? Thanks, thor
        I just found a cheat. If you set $^L = "", the form feeds disappear! Yeah. thor