Begin, End & Rule Sections
Next come action statements, grouped in begin, end, and rule sections.
The heart of a Pikt script is the main processing loop: A line of input (from a proc, file, or logfile) is read in, then acted upon, the next line is read in and acted upon, and so on until the input is exhausted. Before input processing, you might have a begin section, for example to initialize some variables or to take some other preliminary actions. After input processing, you might add an end section, for actions taken at the conclusion of input processing. (You can also achieve additional data processing loops within a Pikt script using a combination of #fopen()/#popen(), #read(), and #fclose()/#pclose().)
In other words:
begin [optional] <statement> <statement> ... [while there's another input line] [optional] rule <statement> <statement> ... rule <statement> <statement> ... ... [endwhile] end [optional] <statement> <statement> ...Note that begin, rule, and end sections are individually optional, but the script must have at least one. That is, you might have a script with only a begin section, or only an end section, or only one or more rule sections, or some combination of the three. Another requirement is that begin must precede rules, and end must follow begin and rules. Here are the possibilities:
begin end begin end rules begin rules rules end begin rules endThe input processing loop comprises one or more rule sections. Strictly speaking, there is never a need to break up the set of input processing statements into separate rule sections, but doing so helps clarify program logic. (A rule line is also a handy place to put comments.) A rule section, then, usually groups together program statements pertaining to a single thing, just one attribute of the current input line.
![]() | 1st page | next page ![]() |