Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Cobol > Re: Did I write...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 57 Topic 4074 of 4195
Post > Topic >>

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

by Robert <no@[EMAIL PROTECTED] > Mar 30, 2008 at 09:09 PM

On Sun, 30 Mar 2008 11:47:14 -0500, "Rick Smith" <ricksmith@[EMAIL PROTECTED]
> wrote:

>
>"MikeB" <MPBrede@[EMAIL PROTECTED]
> wrote in message
>news:408bb0cb-b47e-43b4-b4f0-b604d6c36a3e@[EMAIL PROTECTED]
>[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

A better way to remove leading spaces is:

unstring ip-octet(ip-index1) delimited by all space
    into temp-string, temp-string
string temp-string ':' delimited by space 
   into ip-print-fielld with pointer ip-print-position

If ip-octet had no spaces, it will go to the first temp-string and the
second will be
unchanged. If it did have leading spaces, the first temp-string will be
cleared to spaces,
the word will go into the second mention of temp-string.
 




 57 Posts in Topic:
Did I write a good (efficient) program?
MikeB <MPBrede@[EMAIL   2008-03-30 06:37:28 
Re: Did I write a good (efficient) program?
spambait@[EMAIL PROTECTED  2008-03-30 15:09:03 
Re: Did I write a good (efficient) program?
"Rick Smith" &l  2008-03-30 11:47:14 
Re: Did I write a good (efficient) program?
Robert <no@[EMAIL PROT  2008-03-30 21:09:28 
Re: Did I write a good (efficient) program?
MikeB <MPBrede@[EMAIL   2008-03-30 11:52:44 
Re: Did I write a good (efficient) program?
"HeyBub" <he  2008-03-30 19:47:27 
Re: Did I write a good (efficient) program?
MikeB <MPBrede@[EMAIL   2008-03-30 12:22:30 
Re: Did I write a good (efficient) program?
Robert <no@[EMAIL PROT  2008-03-30 18:44:48 
Re: Did I write a good (efficient) program?
Richard <riplin@[EMAIL  2008-03-31 12:10:23 
Re: Did I write a good (efficient) program?
Robert <no@[EMAIL PROT  2008-03-31 20:40:31 
Re: Did I write a good (efficient) program?
"Rick Smith" &l  2008-03-31 18:20:29 
Re: Did I write a good (efficient) program?
"Michael Mattias&quo  2008-04-01 12:44:49 
Re: Did I write a good (efficient) program?
docdwarf@[EMAIL PROTECTED  2008-04-01 14:29:40 
Re: Did I write a good (efficient) program?
Howard Brazee <howard@  2008-04-01 08:43:48 
Re: Did I write a good (efficient) program?
"Michael Mattias&quo  2008-04-01 16:04:49 
Re: Did I write a good (efficient) program?
Howard Brazee <howard@  2008-04-01 11:08:06 
Re: Did I write a good (efficient) program?
"Pete Dashwood"  2008-04-02 10:44:20 
Re: Did I write a good (efficient) program?
"Michael Mattias&quo  2008-04-01 23:21:29 
Re: Did I write a good (efficient) program?
"Pete Dashwood"  2008-04-02 13:37:38 
Re: Did I write a good (efficient) program?
Clark F Morris <cfmpub  2008-04-01 21:43:15 
Re: Did I write a good (efficient) program?
SkippyPB <swiegand@[EM  2008-04-02 11:50:47 
Re: Did I write a good (efficient) program?
"Michael Mattias&quo  2008-04-02 11:01:28 
Re: Did I write a good (efficient) program?
SkippyPB <swiegand@[EM  2008-04-03 11:46:22 
Re: Did I write a good (efficient) program?
Howard Brazee <howard@  2008-04-03 10:01:01 
Re: Did I write a good (efficient) program?
SkippyPB <swiegand@[EM  2008-04-04 11:08:39 
Re: Did I write a good (efficient) program?
"HeyBub" <he  2008-04-03 18:07:19 
Re: Did I write a good (efficient) program?
"Pete Dashwood"  2008-04-02 10:07:54 
Re: Did I write a good (efficient) program?
Howard Brazee <howard@  2008-04-02 07:53:35 
Re: Did I write a good (efficient) program?
"Pete Dashwood"  2008-04-03 10:40:31 
Re: Did I write a good (efficient) program?
Howard Brazee <howard@  2008-04-03 07:47:45 
Re: Did I write a good (efficient) program?
"Rick Smith" &l  2008-04-02 23:08:22 
Re: Did I write a good (efficient) program?
"Pete Dashwood"  2008-04-04 01:39:13 
Re: Did I write a good (efficient) program?
"Rick Smith" &l  2008-04-03 19:31:14 
Re: Did I write a good (efficient) program?
"Pete Dashwood"  2008-04-04 17:14:34 
Re: Did I write a good (efficient) program?
"Rick Smith" &l  2008-04-04 05:05:35 
Re: Did I write a good (efficient) program?
"Pete Dashwood"  2008-04-04 23:37:21 
Re: Did I write a good (efficient) program?
"Rick Smith" &l  2008-04-04 13:58:33 
Re: Did I write a good (efficient) program?
"Pete Dashwood"  2008-04-05 11:27:41 
Re: Did I write a good (efficient) program?
Howard Brazee <howard@  2008-04-04 07:53:10 
Re: Did I write a good (efficient) program?
"Rick Smith" &l  2008-04-04 11:20:56 
Re: Did I write a good (efficient) program?
Howard Brazee <howard@  2008-04-04 11:46:09 
Re: Did I write a good (efficient) program?
"Pete Dashwood"  2008-04-05 11:53:54 
Re: Did I write a good (efficient) program?
"Pete Dashwood"  2008-04-05 11:41:47 
Re: Did I write a good (efficient) program?
Richard <riplin@[EMAIL  2008-03-31 23:00:30 
Re: Did I write a good (efficient) program?
"tlmfru" <la  2008-04-01 12:15:13 
Re: Did I write a good (efficient) program?
"Pete Dashwood"  2008-04-02 09:41:51 
Re: Did I write a good (efficient) program?
"Pete Dashwood"  2008-04-02 09:30:55 
Re: Did I write a good (efficient) program?
"Rick Smith" &l  2008-04-01 13:01:45 
Re: Did I write a good (efficient) program?
MikeB <MPBrede@[EMAIL   2008-04-01 23:20:50 
Re: Did I write a good (efficient) program?
"Rick Smith" &l  2008-04-02 03:08:22 
Re: Did I write a good (efficient) program?
jnjsle1@[EMAIL PROTECTED]  2008-05-16 07:21:01 
Re: Did I write a good (efficient) program?
jnjsle1@[EMAIL PROTECTED]  2008-05-16 07:31:20 
Re: Did I write a good (efficient) program?
"HeyBub" <he  2008-05-16 10:34:50 
Re: Did I write a good (efficient) program?
jnjsle1@[EMAIL PROTECTED]  2008-05-16 11:21:29 
Re: Did I write a good (efficient) program?
jnjsle1@[EMAIL PROTECTED]  2008-05-16 11:27:44 
Re: Did I write a good (efficient) program?
Robert <no@[EMAIL PROT  2008-05-16 21:13:06 
Re: Did I write a good (efficient) program?
jnjsle1@[EMAIL PROTECTED]  2008-05-16 11:32:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 16:29:08 CDT 2008.