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 row
i.field1
get row
i.field2
if row
i.field2 = '-' then
get row
i.field1
if row
i.field1 = row
i-1.field1 then
row
i.field2=row
i-1.field2
elseif row
i.field1 = row
i+1.field1 then
row
i.field2=row
i+1.field2
else
loop until find a valid entry and use
row
i+x.field2
end if
i also need a count of the consecutive
row
i.field1 which are equal
i hope that somebody can suggest a good solution and thank you for your help! thanks
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.