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


In reply to Re: query linking by CountZero
in thread query linking by ritzi86

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.