Chas Owens wrote:
> On 8/20/07, Mathew Snyder <[EMAIL PROTECTED]> wrote:
>> Paul Lalli wrote:
>>> On Aug 20, 3:10 pm, [EMAIL PROTECTED] (Mathew Snyder) wrote:
>>>> I run a script which creates a small report for different users of a 
>>>> system we
>>>> have here at work.  The report is a simple text document formated with, of 
>>>> all
>>>> things, the format function.  It uses a TOP to create a header for each of 
>>>> our
>>>> customers which a user has worked with.  For some reason the first and 
>>>> only the
>>>> first write of the TOP results in a double write.
>>>>             write TIMESHEET_TOP;
>>> <snip>
>>>
>>>>                     write TIMESHEET;
>>>> It gets that double header.  Again, everything else gets only the one, 
>>>> expected,
>>>> header.  Anyone have any ideas as to why the first one always prints twice?
>>> Because Perl is smarter than you're giving it credit for. :-P
>>>
>>> $ perldoc -f write
>>>      write FILEHANDLE
>>>      write EXPR
>>>      write
>>>              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.
>>>
>>> Key phrase there: "top of form processing is handled automatically".
>>> That is, you don't have to write the header your self.  Perl does that
>>> for you, on each new page the report is printed to.  You just define
>>> the format header.  Let Perl decide when it needs to be written.
>>>
>>> Remove the write TIMESHEET_TOP line.
>>>
>>> Paul Lalli
>>>
>>>
>> Paul,
>>
>> Thanks for the help.  However, doing what you said results in the output 
>> having
>> only one header and the list output for each customer going under it.  It
>> doesn't create a header for each customer.
>>
>> Mathew
> 
> Header writes are controlled by $- (aka $FORMAT_LINES_LEFT under the
> english pragma).  When $- is zero a header gets written and $- is set
> back to the number of lines to print before a header is printed.  Or
> at least that is how I remember it.
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> my $customer;
> my $id   = 5000;
> my $time = "12:30:00";
> 
> for $customer (qw<foo bar baz>) {
>         $id++;
>         write;
>         $- = 0;
> }
> 
> format STDOUT_TOP =
> Customer @<<<<<<<<
> $customer
> .
> 
> format STDOUT =
> @>>>>>, @<<<<<<<<<<
> $id, $time
> .
> 

It would appear that for all but the first iteration, this is happening.
However, something during the first time through seems to cause the flag to not
be what it should.

I've tried changing where the TOP is in the script, when it gets written, the
value of $- entering the loop... Nothing seems to work.

Keep up with me and what I'm up to: http://theillien.blogspot.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to