[comp.lang.perl] Problems with format...

pda@rsiatl.UUCP (Paul D. Anderson) (04/06/90)

I have been working with Perl's format statement and have been experiencing
a bit of trouble with interleaving of IO.  It appears that some data in 
the body of the output is put in a magical buffer that doesn't get flushed
until the output is closed.  The only thing that I am doing that is a bit
unusual is embedding escape sequences in the format strings to cause a 
laser printer to change fonts...  The end effect is that about the first 
1 to 5 lines of text output by 'format OUT =' setup endup in the output file
after all other text has been sent.

Can anyone see anything that might cause such a problem?  'tabexp' is a 
tab expansion program.  All program output is directed to a file or the
laser printer under normal operation.  The 'x.' in the format statements is
really just a '.' in normal operations.

The following is essentially the structure of the program:

$COMPRESS="^[abcdefghijkl";
$RESET="^[E";

format top =
@<
$RESET
	Some text to be presented
@<<<<<<<<<<<<
$COMPRESS
x.

format OUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$data
x.

foreach $a (<*>) {
	open(IN,$a);
	open(OUT,'|tabexp');
	while (<IN>) {
		$data = $_;
		write(OUT);
	};
	close(IN); close (OUT);
};

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (04/12/90)

I have dim recollections of such a problem somewhere sometime with somebody's
stdio.  What version of perl are you running under what version of what os
running on what kind a beastie?

Do you do any forks?  What happens if you say "select(OUT); $| = 1;"?

Larry

pda@rsiatl.UUCP (Paul D. Anderson) (04/12/90)

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:

>I have dim recollections of such a problem somewhere sometime with somebody's
>stdio.  What version of perl are you running under what version of what os
>running on what kind a beastie?
>Do you do any forks?  What happens if you say "select(OUT); $| = 1;"?

I just went back and put in the select(OUT) and $|=1.  It doesn't change
the output- but I did inspect the output stream more closely.  What appears
to be happening is that close(OUT) doesn't reset the top of page counter.
On each subsequent page, more and more lines of the body appear *before*
the top of page header.  I suspect this is probably actually the case-
since I close the output stream on each iteration of the loop to force a
new top-of-page.  

I'm doing no forks, save the open(OUT,'|tabexp');.  I'm running current
patchlevel of Perl.  The OS is Interactive Unix on a 386 PC.  Hope that 
helps.

-paul
-- 
* Paul Anderson * Crossroads Computing * (404) 565-0761 * emory!rsiatl!pda * 

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (04/13/90)

In article <1764@rsiatl.UUCP> pda@rsiatl.UUCP (Paul D. Anderson) writes:
: What appears
: to be happening is that close(OUT) doesn't reset the top of page counter.
: On each subsequent page, more and more lines of the body appear *before*
: the top of page header.  I suspect this is probably actually the case-
: since I close the output stream on each iteration of the loop to force a
: new top-of-page.  

OK, you have to reset that counter yourself--close won't do it.  In fact,
that's how you force a top of form in the middle of a report.  Just say

	$- = 0;

and that sets the number of writable lines left on the current page to 0.

Larry