Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I have the requirement to print the first record of the $sql_pr based on differnent values of "seg_dtl_id" so that when the "while loop" ends, i have the file with the pan_id belongs to respective "seg_dtl_id" printed in the respective column seperated by "|" like below. 8000|6000|7000 8001|6001|7001 8002|6002|7002 8003|6003|7003 8004|6004|7004 here 8000,8001,8002,8003,8004 are pan_ids belong to a single seg_dtl_id and so and so forth. i can make it with the help of below code but the problem arises when it comes to performance as the code executes the same sql multiple times.Say if number of records are 1 million, the sql has to run 1 million times thereby making performance issues. please note am using basic version of perl (perl5/lib/5.00503) and guide me to reconstruct the code to overcome this problem.

open(file,"> Segmentation.txt"); my $index = 0; my $n = 0; my $sql_ct = "select max(count(pan_id)) from seg_dtl_panelist where s +eg_id ='1' group by seg_dtl_id, seg_id"; my $rs_ct = $db->query($sql_ct); while ($n < $$rs_ct[0][0]) { $sql = "select seg_dtl_id from segmentation where seg_id = '1'"; $rs = $db->query($sql); foreach (@$rs) { my $dtl_id = $$_[0] ; $sql_pr = "select pan_id from seg_dtl_panelist where seg_dtl_id = '$ +dtl_id' and seg_id = '1'"; $rs_pr = $db->query($sql); print file "$$rs_pr[$index][0]|"; } print file "\n"; $index++; $n++; } close (file);

In reply to Need to Improve Performance by Naveen_learn

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and !@monks...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (8)
    As of 2018-06-18 07:49 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (109 votes). Check out past polls.