Re: Did I write a good (efficient) program?




"MikeB" <MPBrede@xxxxxxxxx> wrote in message
news:408bb0cb-b47e-43b4-b4f0-b604d6c36a3e@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[snip]
In the meantime,
I'd like to hear from members of this group if I could have written
cleaner, leaner and more efficient COBOL.

I can not say that it meets all the criteria but here is another
way to have done it. It uses intrinsic functions and STRING
to do ... uh ... character and string manipulation.

Showing the PROCEDURE DIVISION only.
-----
PROCEDURE DIVISION.
* Expand 16 byte IP-ADDRESS to
* 32 character hex display in IP-OCTETS
move 1 to ip-octets-ptr
perform
varying ip-index1 from 1 by 1
until ip-index1 > 16
compute hex-index1 =
function ord (ip-address(ip-index1:1))
string
hex-byte (hex-index1) delimited by size
into ip-octets
with pointer ip-octets-ptr
end-perform

* IP V6 addresses are formatted as 16-bit "octets" delimited by
* colons (":") and with leading zeroes suppressed.
*
* Leading zeros are replaced by spaces then
* formatting is done in reverse to suppress these spaces

MOVE 1 TO IP-PRINT-POSITION
MOVE SPACES TO IP-PRINT-FIELD

PERFORM VARYING IP-INDEX1 FROM 8 BY -1
UNTIL IP-INDEX1 < 1
inspect ip-octet(ip-index1)(1:3)
replacing leading zeros by spaces
string
function reverse (ip-octet(ip-index1))
delimited by spaces
":" delimited by size
into ip-print-field
with pointer ip-print-position
END-PERFORM

* Reverse the string
subtract 2 from ip-print-position
move function reverse (ip-print-field(1:ip-print-position))
to ip-print-field
stop run
.
-----


.