in reply to query linking

I got the following answer in my mailbox from ritzi86:
Hi what I meant by linking and all is that, as you can see, the SQL query is in two parts, separated by a Perl script. Now when I run the script the query should run as 1 which it did not. So I want to know is it because of something in the Perl script?

(edited the text for typos and so)

As far as I can tell, neither the "first" nor the "second" SQL queries ever run. Actually there is only one SQL query. There seems to be a "fixed" part (everything before # Add list of interesting contracts) and a dynamic part which is written by the foreach loop. Then follows another (semi-)fixed part which is tacked to the previous part. ... And that's it.

No code to run the SQL code, it must be somewhere else in the script and if what we have seen is in any way an example of how this script is written, I have no desire to look at it.

For instance, the dynamic part of the SQL query can be much clearer written as one line of code:

$sqlcmd .= 'AND (' . join 'OR ', map {"cc.contract_type = $_ "} sort k +eys %contracts;
No $i iterator-variable is necessary and no need to keep a $contract_count variable around (and coordinated); no risk of having a subtle "off by one" (did we start counting from zero or one?) error. I'm almost certain the sort function is superfluous: database-engines don't care whether the query is sorted. The internal optimizer will take care of such things.

Quite a lot of comments for a small snippet of code. One wonders (and shudders) if one thinks of the whole script: obviously there are things no sane man is meant to know.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James