[comp.lang.perl] top-of-form w/o formfeed

jv@mh.nl (Johan Vromans) (11/21/90)

Using write: how can I force the $^ format to be printed without a
formfeed character being inserted?

	Johan
-- 
Johan Vromans				       jv@mh.nl via internet backbones
Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62911/62500
------------------------ "Arms are made for hugging" -------------------------

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (11/22/90)

In article <1990Nov20.222930.1152@squirrel.mh.nl> Johan Vromans <jv@mh.nl> writes:
: Using write: how can I force the $^ format to be printed without a
: formfeed character being inserted?

Depends on what you mean.  If you mean that you want to write the top
of form format in the middle of a page, something like

	{
	    local($~) = $^;
	    write;
	}

should work.

If you mean you want to have $^ do top-of-page with line-feeds rather
than a form feed (ala nroff), there's no direct way to do that, other than
keeping track of the number of lines on the page yourself and printing
out a string of newlines at the right moment.  Either that, or running
it through some output filter:

	$pid = open(OUT, "|-");
	die "Can't fork: $!\n" unless defined $pid;
	unless ($pid) {			# we're the child process
	    $/ = "\f";
	    while (<>) {		# slurp each page
		chop;			# delete form feed
		$count = tr/\n/\n/;	# count newlines
		print $_, "\n" x (66 - $count);
	    }
	    exit;
	}
	...
	write OUT;			# or dup to STDOUT

This latter trick can also be used to massage headers into footers.

Larry

jv@mh.nl (Johan Vromans) (11/25/90)

In article <10500@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
   In article <1990Nov20.222930.1152@squirrel.mh.nl> Johan Vromans <jv@mh.nl> writes:
   : Using write: how can I force the $^ format to be printed without a
   : formfeed character being inserted?

   Depends on what you mean.  If you mean that you want to write the top
   of form format in the middle of a page, something like

	   {
	       local($~) = $^;
	       write;
	   }

   should work.

That's what I meant. I've been thinking to use "$~ = $^; write" but I
discarded this solution since it needs knowledge of the current output
format. I didn't think of localizing $~ .

While we're on the subject:

 - The fact that the formfeed is hard-coded bugs me. Almost anything
   in perl can be controlled/modified using special variables.
 - The possibility to have footers is still a wish. If you forbid the
   use of variable-line formats (both ^ and ~) in footers, it
   shouldn't be that hard...

	Johan
-- 
Johan Vromans				       jv@mh.nl via internet backbones
Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62911/62500
------------------------ "Arms are made for hugging" -------------------------