Top-of-Page Formats are meant for hardcopy devices, but you can achieve the results you want with a simple hack: make $= equal to the number of lines you are about to print plus 2 for the numbers of lines in INDEXFILE_TOP. Here is an example:
The only things that really bugs me about this code is having to hard code the number of lines in INDEXFILE_TOP. There might be a way to derive this number, i'll be on the lookout for it (anybody knows...feel free to share ;))use strict; my ($prog,$desc,$pages,$date,$file); my @line1 = ( qq|prog desc pages data file\n|, qq|foo blah 5 bar foo.txt\n|, qq|bar blah 5 baz bar.txt\n|, qq|baz blah 5 qux baz.txt\n|, ); my @line2 = ( qq|prog desc pages data file\n|, qq|foo blah 5 bar foo.txt\n|, ); $~ = 'INDEXFILE'; write_2_file(@line1); write_2_file(@line2); sub write_2_file { $= = 2 + @_; for (@_) { chomp; ($prog,$desc,$pages,$date,$file) = split; write; # to STDOUT for this example } } format INDEXFILE_TOP = Program Description Pages Date Filename ------------------------------------------------ . format INDEXFILE = @<<<<< @<<<<<<<<<<<<<<<<<< @<<<<< @<<<<< @<<<<<<<<<<< $prog, $desc, $pages, $date, $file .
UPDATE: Doh! Looks like rinceWind has a much cleaner answer.
Change '$= = 2 + @_' to '$- = 0' in the above example for a more robust subroutine. rinceWind++
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to (jeffa) Re: Format Question
by jeffa
in thread Format Question
by nimdokk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |