hello, today I'm afflicted with a problem I'm finding hard to grasp and i hope that the more expert will be able to guide me.
basically i need to pull out data from a database and based on comparisons update fields in the db. in principle it sounds simple, but I'm struggling with the code and possibly the logic...
if it was for a few rows i thought that i could execute the query and pas the values to an array, then manipulate the array, however for thousands of columns this might not be the most efficient way (please argue against this if i'm wrong!)
a different way is to pull out values in chunks of rows, but if you look at the example below i don't have any way of checking in advance how many rows contain invalid chars.
here is an example myTable containing:
Field1, Field2, Field3, Field4 ....
100, abc, 4
100, -, 3
105, -, 5
105, -, 5
105, def, 3
101, fgh, 4
101, -, 4
....etc.

what i thought would be more efficient is to take one row at a time and compare the content with the one above and the one below (or row+i if the value returned is still invalid), but have no clue how to keep the loop clean.
here is my pseudo-code:

- create connection,
- execute query to get no of rows (i)

start loop
- execute query for row i,
get rowi.field1
get rowi.field2

if rowi.field2 = '-' then
get rowi.field1
if rowi.field1 = rowi-1.field1 then
rowi.field2=rowi-1.field2
elseif rowi.field1 = rowi+1.field1 then
rowi.field2=rowi+1.field2
else
loop until find a valid entry and use
rowi+x.field2
end if

i also need a count of the consecutive
rowi.field1 which are equal
i hope that somebody can suggest a good solution and thank you for your help! thanks

In reply to DBI efficient loop? by lorenzov

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.