IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
CLASS UPPER-CASE-ENGLISH-LETTERS IS
'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 UC-COUNTER PIC 99.
PROCEDURE DIVISION.
INSPECT "My dog has fleas"
TALLYING UC-COUNTER FOR ALL UPPER-CASE-ENGLISH-LETTERS.
DISPLAY UC-COUNTER " UPPER CASE CHARACTERS".
STOP RUN.
Doesn't work, of course, as INSPECT doesn't allow CLASSes to be used.
Even so ...
In article <60d51dc4-dcc6-4878-a351-487008c76db1n@googlegroups.com>,
Bruce Axtens <bruce.axtens@gmail.com> wrote:
(SNIP)
Doesn't work, of course, as INSPECT doesn't allow CLASSes to be used.
Even so ...
A question, Mr Axtens: is the goal of the exercise to get the count of characters or is it to get the count of characters using INSPECT?
Consider:
05 TEST-BED PIC X(20) VALUE SPACES.
05 WS-TEST-AREAS.
10 WS-TEST-ALPHA PIC X VALUE SPACES.
88 UCASE-ALPHA VALUES 'A' THRU 'H', 'I' THRU 'R', 'S' THRU 'Z'.
88 LCASE-ALPHA VALUES 'a' THRU 'h', 'i' thru 'r', 's' thru 'z.
88 A-SPACE VALUE X'40'.
88 SPECL-CHAR VALUE X'05', X'62'.
MOVE 'My dog has fleas' TO TEST-BED.
MOVE UKELELE-PLAYER TO ANOTHER-NEIGHBORHOOD.
PERFORM VARYING TALLY FROM 1 BY 1 UNTIL TALLY > (LENGTH OF TEST-BED)
MOVE TEST-BED(TALLY:1) TO WS-TEST-ALPHA
IF UCASE-ALPHA ADD 1 TO UC-CTR
IF LCASE-ALPHA ADD 1 TO LC-CTR
... and so on. First, I was taught that you have to be very careful
coding INSPECTS because some shops wouldn't look too closely when they
found something 'that worked'... and INSPECT (SORT, too) work really in
batch but less so in the online regions.
Next, this method tries to restrict hardcoding out of the PROCEDURE
DIVISION. It all goes into WORKING-STORAGE until there's so much stuff
that needs to be checked they redesign the code to load tables during HOUSEKEEPING.
DD
On 11/19/2022 8:05 AM, docdwarf@panix.com wrote:
In article <60d51dc4-dcc6-4878-a351-487008c76db1n@googlegroups.com>,
Bruce Axtens <bruce.axtens@gmail.com> wrote:
(SNIP)
Doesn't work, of course, as INSPECT doesn't allow CLASSes to be used.
Even so ...
A question, Mr Axtens: is the goal of the exercise to get the count of
characters or is it to get the count of characters using INSPECT?
Consider:
05 TEST-BED PIC X(20) VALUE SPACES.
05 WS-TEST-AREAS.
10 WS-TEST-ALPHA PIC X VALUE SPACES.
88 UCASE-ALPHA VALUES 'A' THRU 'H', 'I' THRU 'R', 'S' THRU 'Z'.
88 LCASE-ALPHA VALUES 'a' THRU 'h', 'i' thru 'r', 's' thru 'z.
88 A-SPACE VALUE X'40'.
88 SPECL-CHAR VALUE X'05', X'62'.
MOVE 'My dog has fleas' TO TEST-BED.
MOVE UKELELE-PLAYER TO ANOTHER-NEIGHBORHOOD.
PERFORM VARYING TALLY FROM 1 BY 1 UNTIL TALLY > (LENGTH OF TEST-BED)
MOVE TEST-BED(TALLY:1) TO WS-TEST-ALPHA
IF UCASE-ALPHA ADD 1 TO UC-CTR
IF LCASE-ALPHA ADD 1 TO LC-CTR
... and so on. First, I was taught that you have to be very careful
coding INSPECTS because some shops wouldn't look too closely when they
found something 'that worked'... and INSPECT (SORT, too) work really in
batch but less so in the online regions.
I'm pretty sure if you use this method, you could define your own CLASS
TEST alphabets and use them. For example,
EVALUATE TRUE
WHEN TEST-BED (TALLY:1) IS MY-UPPER-CASE
ADD +1 TO UC-CTR
WHEN TEST-BED (TALLY:1) IS MY-LOWER-CASE
ADD +1 TO LC-CTR
END-EVALUATE
You don't want to use the built-in ALPHABETIC-UPPER and ALPHABETIC-LOWER >classes because they include SPACE as an alphabetic character, which I >presume must be simultaneously upper-case and lower-case.
Next, this method tries to restrict hardcoding out of the PROCEDURE
DIVISION. It all goes into WORKING-STORAGE until there's so much stuff
that needs to be checked they redesign the code to load tables during
HOUSEKEEPING.
We had a style rule to reduce or eliminate hardcoding literals in the >PROCEDURE DIVISION. It was supposed to help prevent certain kinds of
logic errors. I recall a billing program that had three instances of >multiplying a transaction count by a billing rate of a half-cent. If
the half-cent billing rate was a literal and needed to be changed to
.006, what are the odds a maintenance programmer would change two of the >literals and miss the third?
On 11/19/2022 8:05 AM, docdwarf@panix.com wrote:
In article <60d51dc4-dcc6-4878-a351-487008c76db1n@googlegroups.com>,
Bruce Axtens <bruce.axtens@gmail.com> wrote:
(SNIP)
Doesn't work, of course, as INSPECT doesn't allow CLASSes to be used.
Even so ...
A question, Mr Axtens: is the goal of the exercise to get the count of
characters or is it to get the count of characters using INSPECT?
Consider:
05 TEST-BED PIC X(20) VALUE SPACES.
05 WS-TEST-AREAS.
10 WS-TEST-ALPHA PIC X VALUE SPACES.
88 UCASE-ALPHA VALUES 'A' THRU 'H', 'I' THRU 'R', 'S' THRU 'Z'.
88 LCASE-ALPHA VALUES 'a' THRU 'h', 'i' thru 'r', 's' thru 'z.
88 A-SPACE VALUE X'40'.
88 SPECL-CHAR VALUE X'05', X'62'.
MOVE 'My dog has fleas' TO TEST-BED.
MOVE UKELELE-PLAYER TO ANOTHER-NEIGHBORHOOD.
PERFORM VARYING TALLY FROM 1 BY 1 UNTIL TALLY > (LENGTH OF TEST-BED)
MOVE TEST-BED(TALLY:1) TO WS-TEST-ALPHA
IF UCASE-ALPHA ADD 1 TO UC-CTR
IF LCASE-ALPHA ADD 1 TO LC-CTR
... and so on. First, I was taught that you have to be very careful
coding INSPECTS because some shops wouldn't look too closely when they
found something 'that worked'... and INSPECT (SORT, too) work really in
batch but less so in the online regions.
I'm pretty sure if you use this method, you could define your own CLASS
TEST alphabets and use them. For example,
EVALUATE TRUE
WHEN TEST-BED (TALLY:1) IS MY-UPPER-CASE
ADD +1 TO UC-CTR
WHEN TEST-BED (TALLY:1) IS MY-LOWER-CASE
ADD +1 TO LC-CTR
END-EVALUATE
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 106:31:32 |
Calls: | 6,700 |
Files: | 12,232 |
Messages: | 5,350,363 |