INSPECT in COBOL
INSPECT reads or rewrites characters in place: count the DOTs, then patch the tape.
IDENTIFICATION DIVISION.
PROGRAM-ID. INSPECT-TALLYING.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SIGNAL-TAPE PIC X(20) VALUE "DOT DASH DOT DOT PAD".
01 DOT-COUNT PIC 99 VALUE 0.
PROCEDURE DIVISION.
*> INSPECT counts or rewrites characters in place.
INSPECT SIGNAL-TAPE TALLYING DOT-COUNT FOR ALL "DOT"
DISPLAY "DOT appears " DOT-COUNT " times"
INSPECT SIGNAL-TAPE REPLACING ALL "PAD" BY "END"
DISPLAY "Tape now: " SIGNAL-TAPE
STOP RUN.
How it works
TALLYING DOT-COUNT FOR ALL "DOT"counts every occurrence into a field.- The count arrives without a loop — one verb scans the whole field.
REPLACING ALL "PAD" BY "END"edits the tape where it sits.
Keywords and builtins used here
DATADISPLAYDIVISIONIDENTIFICATIONINSPECTPROCEDURESECTIONSTOP
The run, in numbers
- Lines
- 13
- Characters to type
- 440
- Tokens
- 53
- Three-star pace
- 40 tpm
At the three-star pace of 40 tokens a minute, this run takes about 80 seconds.
Step 3 of 3 in Tables & strings, step 21 of 27 in Language basics.