Click here to Skip to main content
15,884,629 members

Comments by Robert g Blair (Top 6 by date)

Robert g Blair 1-Dec-16 23:02pm View    
You can test this code here: https://www.tutorialspoint.com/compile_cobol_online.php
Robert g Blair 1-Dec-16 22:04pm View    
David - its very hard to compare.

If you remove the Display statement it will run in less than a millisecond on, say, a Fujitsu mainframe.
It runs in a couple milliseconds on a Ubuntu box with GnuCobol.

But what I coded was very compiler friendly - hard coded literals, single statement etc.

FYI: When I say "intrinsic" I mean in this sense: https://en.wikipedia.org/wiki/Intrinsic_function
Ie, the compiler is optimizing the string handling involved in the INSPECT statement execution. Whether it does it well or no is a function of the compiler's competence.
Robert g Blair 1-Dec-16 19:42pm View    
Chris:

I believe it is appropriate to give an award for "Least Lines of Code".

A very objective metric, and serves the higher purpose of combating code-bloat.
Robert g Blair 1-Dec-16 19:33pm View    
Well, you could do a lot to make it more gooderer:

- The string literals can be variables, which you could get from an input source, eg, a database, an input form, xml, whatever.

- You can also use TALLYING and BEFORE INITIAL ...

But case - case in COBOL is not so easy.
Sorry, but for COBOL solutions you have to choose a case. Upper or lower.

Case is merely a social construct y'know :)
Robert g Blair 1-Dec-16 15:59pm View    
David - my COBOL solution took just 15 minutes to write (and I haven't coded COBOL for many years).

And it will run blindingly fast. Everything is handled in a single intrinsic, compiler optimized, command.

I didn't add the "extra" bits you have, because they weren't in the spec, and I didn't want to spend any time on it.

To implement "pooppoop" -> "p**pp**p" is a simple REPLACING operation.

To implement "poopoopoop" -> "p**p**p**p" would involve a REPLACING "poo" BEFORE INITIAL "p**" - and recursing.