From: olgaa@koonda.acci.com.au (Olga Aronov)
Subject: Re: perl script wanted for word manipulation
Keywords: word alphabetization, letter count
Organization: School of Engineering and Applied Sciences, UCLA
Date: Mon, 5 Oct 1992 23:57:08 GMT

Sorry, if my question looks trivial but I am the very beginner in perl.
I wrote a simple programme for printing a formatted output using the
sources ("camel" book p. 109). I can' t make it print the header at the
top of the page and the footer at the bottom of the same one. It changes 
the order to $head, $body, $foot but places footer(date) on the next page.
The output of the programme looks like this:

--------------------------------
	PHONEBOOK                                               page 1

	...        
	...
	...

^L
                                                                Mon Oct  5 16:2
        PHONEBOOK                                               page   2

	...
	...
	...
	
^L
                                                                Mon Oct  5 16:2 
        PHONEBOOK                                               page   3                           
	.
	.
	.
^L
                                                                Mon Oct  5 16:2 
	PHONEBOOK						page   6
							
	...
	...
	...

								Mon Oct  5 16:2
-----------------------------------

I tried to print out $- before, between and after all the parts. It's always "0".
It's non-zero inside the "$body". If the input file is short enough for one
page it works as supposed. What am I doing wrong? Any help would 
be appreciated.
I'm using version 4, patch level 0.

****     Text of the programme    ***

#!/usr/local/bin/perl

format TOP =
        PHONEBOOK                      				page @>>
                                                       		$%
FOOTER
                                              			@>>>>>>>>>>>>>>
                                                       		$date
FOOTER
.

format OUT =

~       @<<<<<  @<<<<<<<<  @<<<<<<<<<<<<<<<        ^<<<<<  ^<<<<<<<<  ^<<<<<<<<<<<<<<<
        $title  $fname     $lname                  $title1 $fname1    $lname1
~       @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<            ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $comp                                      $comp1
~       @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<            ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $pos                                       $pos1
~       @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<            ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $add1                                      $add11
~       @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<            ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $add2                                      $add21
~       @<<<<<<<<<<<<<<<   @>>>>   @>>>>           ^<<<<<<<<<<<<<<<   ^>>>>   ^>>>>
        $city              $state  $pcode          $city1             $state1 $pcode1
~       Tel. @<<<<<<<<<<<<<<<                      Tel. ^<<<<<<<<<<<<<<<
        $tel                                       $tel1
~       Fax  @<<<<<<<<<<<<<<<                      Fax  ^<<<<<<<<<<<<<<<
        $fax                                       $fax1

.


require "ctime.pl";
$date = &ctime(time);
open (PEOPLE, "people");
# open (STDOUT, "| lpr -Pu723b1");

FORK: {
	pipe(READ, WRITE);
            if ($pid = fork) {
		close(WRITE);
		$pid1 = open(OUT, "|-");
		if (!$pid1) {
	            $/ = "\f";
       		    $* = 1; 
        	    while (<STDIN>) {
                        ($head, $foot, $body) = split(/^FOOTER/);
                        print $-, $head, $-, $body, $-, $foot, $-;     # <<<<< $- always "0"
                    }
		} else {
	    	    select(OUT); $^ = 'TOP'; $~ = 'OUT'; 
            	    while (<READ>) {
			($title, $fname, $lname, $comp, $pos, $add1, $add2, $city, $state, $pcode, $tel, $fax, $title1, $fname1, $lname1, $comp1, $pos1, $add11, $add21, $city1,$state1, $pcode1, $tel1, $fax1) = split(/;/, $_);
			print $-;          # <<<<<<< $- is non-zero
                	write(OUT);
            	    }
		}
        } elsif (defined $pid) {
            close READ;
            select(WRITE); $| = 1;
            $count = 0;
            while (<PEOPLE>) {
                if ($count == 0) {$tmp = ''; chop; $tmp .= $_; $count++; next; }
                if ($count == 1) {$tmp .= $_; $count = 0; print WRITE $tmp; }
            }
	exit;
        } elsif ($! =~ /No more process/) {sleep 5; redo FORK; }
        else {die "Can't fork: $!\n"; }
}
exit;
Newsgroups: comp.lang.perl