You have a lot of options above for handling this in code, but personally I would suggest you handle it directly in the database.

I don't know what columns $row[3] and $row[4] represent, but your code is doing a mapping between the two, so create a table to hold the pairs. Something like:

create table curtisb_map ( row3_code varchar(20) -- pure guess , row4_code varchar(20) -- purer guess , primary key (row3_code, row4_code) );
Then populate the table with your if-else data above, and you can just return both with a single select:
select s.*, m.row_3_code from staging.staging_prepouics s inner join curtisb_map m on m.row3_code = s.whatever

The advantage with this approach is that the data is in the database where it belongs, instead of half in the database and half in the code. The next maintenance programmer that comes along will thank you profusely when she finds the mapping right alongside the data. And the bonus is that this is likely to run much faster.

As an aside, your code has something that makes me cringe every time I see it: select * is bad enough, but it's made worse by the assumption of column order (i.e., you're hoping that $row[3] and $row[4] are what you think they are). Do yourself a favor, call out the column names explicitly, and bind the results to meaningful variables. Sooner or later, this practice will bite you.


In reply to Re: Updating database question by VSarkiss
in thread Updating database question by curtisb

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.