Use pseudocode to get a better general grasp of the problem.
First, restate your project description more accurately (in English). Only one of the three things you actually do when the current line is a chapter end. Here's the best I could make of it:
Then translate that to pseudocode. I don't really recommend using obscenely long variable and subroutine names, but the point is that you should factor out the little pieces so that you can look at the structure of the loops and conditionals all at once.
my $pages_this_chapter = 0; while (<IN>) { if (current_line_is_the_kdkhost_line()) { next } # Don't forget the special case # if (current_line_is_a_chapter_end() || $. == 1) { print OUT $chapterization_command; $pages_this_chapter = 0; next; # ??? } if (current_line_starts_a_new_page()) { $pages_this_chapter++; if ($pages_this_chapter == 3) { print OUT $send_to_binder } } if ($pages_this_chapter <= 2) # 3? { change_the_paper_output_tray() } print OUT; }
That's not exactly what you want, but you get the idea. Now fill in the blanks. Remember that $_ and $. are visible everywhere. (You may prefer to change your subroutines to accept the current line and/or line number as arguments instead of peeking at $_ and $. .)
sub current_line_is_the_kdkhost_line { m/^%KDKHost:/; } sub current_line_is_a_chapter_end { m!<</OutputType \(\)>>setpagedevice!; } sub current_line_starts_a_new_page { /%%BeginPageSetup/; } sub change_the_paper_output_tray { m!<</OutputType\(Stacker\)>>setpagedevice! and s/Stacker/top/; }
--
LP^>
In reply to Re: Can I do an "inner read"?
by TilRMan
in thread Can I do an "inner read"?
by digger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |