digger has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; #since first page gets treated like the end of a chapter #we start with end_chapter being true. my $end_chapter = 1; my $time = time(); #line required to redirect output to postprocessor (ie perfectbinder) my $to_pp = '<</OutputType(postprocessor)>>setpagedevice \n'; #line to force chapterization my $chapter = 'true [] /110pProcs /ProcSet findresource /setchapters g +et exec \n'; #my $outfile = "/var/spool/drop_box/autoq/".$time.".print"; my $outfile = "d:/customer files/WPS/Quint.out"; my $infile = $ARGV[0]; open (OUT, ">".$outfile) or die "Can't create temp file!!!!!!!!!"; open (IN, "<".$infile); while (<IN>){ #if its the KDKHost line, skip it my $line = del_KDKHost($_); #handle chapter endings - currently denoted by null OutputType $line = chapterize($line); if ($end_chapter) { handleSeps(); } else { print OUT "$line"; } } sub del_KDKHost { #if this the KDKHost line, delete it my $line = shift; if ($line =~ m/^%KDKHost:/){ $line = ""; } return $line; } sub chapterize { my $line = shift; if ($line =~ m!<</OutputType \(\)>>setpagedevice!) { $line = $chapter; } $end_chapter = 1; return $line; } sub handleSeps { #if we just made a chapter, or this is the first page of the file #we have to make the next 2 pages come out of the top exit my $counter= 0; #if this is the pagenumber line, increment counter #we only need work with 2 pages while (<IN> && $counter<=3) { #if we have started a new page #increment page counter and if we are on the 3rd page #since chapter break, insert line for output to perfect binder if ($_ =~ /%%BeginPageSetup/){ print "STARTED NEW PAGE"; $counter++; if ($counter==3){ $_ .= "\n $to_pp"; $counter = 0; } #if it is the OutputType line for this page, change to top out +put elsif ($_ =~ m!<</OutputType\(Stacker\)>>setpagedevice!){ $_ =~ s/Stacker/top/; } } print OUT $_; } $end_chapter = 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can I do an "inner read"?
by revdiablo (Prior) on Mar 10, 2004 at 22:18 UTC | |
|
Re: Can I do an "inner read"?
by kappa (Chaplain) on Mar 11, 2004 at 13:35 UTC | |
by digger (Friar) on Mar 11, 2004 at 15:04 UTC | |
|
Re: Can I do an "inner read"?
by Roy Johnson (Monsignor) on Mar 10, 2004 at 22:17 UTC | |
by digger (Friar) on Mar 11, 2004 at 14:48 UTC | |
|
Re: Can I do an "inner read"?
by TilRMan (Friar) on Mar 11, 2004 at 01:44 UTC | |
|
Re: Can I do an "inner read"?
by captain_haddock (Novice) on Mar 12, 2004 at 16:11 UTC | |
by digger (Friar) on Mar 12, 2004 at 17:19 UTC |