home *** CD-ROM | disk | FTP | other *** search
/ ftp.cse.unsw.edu.au / 2014.06.ftp.cse.unsw.edu.au.tar / ftp.cse.unsw.edu.au / pub / doc / languages / perl / nutshell / ch3 / footers < prev    next >
Encoding:
Text File  |  1992-10-18  |  989 b   |  37 lines

  1. #!/usr/bin/perl
  2.  
  3. format TOP =
  4. Camel Fight Digest                          @>>>>>>>>>>>>>>>>>>
  5.                         $date
  6.  
  7. Who                                   Winner
  8. FOOTER
  9. @<<<<<<<<<<<<<<<<<           @|||        @>>>>>>>>>>>>>>>>>>>>>
  10. $sponsor                      $%         $whose_pool
  11. FOOTER
  12. .
  13.  
  14. format OUT =
  15. @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<    @<<<<<<<<<<<<<<<<<<<<<<<<
  16. $who                                  $winner
  17. .
  18.  
  19. # Open pipe to a child.
  20.  
  21. $pid = open(OUT,"|-");
  22. if (!$pid) {                        # We're the child process.
  23.     $/ = "\f";                      # Slurp entire page in.
  24.     $* = 1;                         # Multi-line pattern match.
  25.     while (<STDIN>) {
  26.     ($head,$foot,$body) = split(/^FOOTER/);
  27.     print $head,$body,$foot;    # Rearrange page's anatomy.
  28.     }
  29. }
  30. else {                              # We're the parent process.
  31.     select(OUT); $^ = 'TOP'; $~ = 'OUT';
  32.     while (<INPUT>) {
  33.     # Your code here.
  34.     write(OUT);                 # Pretend footer is header.
  35.     }
  36. }
  37.