If you're using a version of DBI later than 1.08, you don't need the initial undef when you call bind_columns.

You can also substitute $sth4->fetch() for $sth4->fetchrow() and get rid of @row4:

while ($sth->fetch()) { # do comparison }
If i understand your code, you have a list of site numbers in @array that may or may not match results from the database. If the first item of the sites array matches the first row of the database result, you want to modify it. Otherwise, you want to delete.

Where I'm confused is the relationship of the array and the db results. If there's an off-by-one in either, the rest of the results will be skewed.

It seems to me to make more sense to test for the existence of database results in the sites array, which could be done in one of two ways.

Keeping your code mostly similar, we build a hash instead of an array:

my %sites_list; @sites_list{split(" ", $sites)} = (); # hash slice for quicker +lookup while ($sth4->fetch()) { if (exists $sites_list{$newSiteNumber}) { print "modify!"; } else { print "delete!"; } }
The other option would be to let your database do the work, splitting and joining $sites to form a VALUES IN ( ) clause for your SQL statement. Depending on how familiar you are with SQL and Perl, you may prefer one approach over the other.

Or I could be completely misunderstanding your intent here, in which case you get double your money back.


In reply to Re: Parsing Arrays II by chromatic
in thread Parsing Arrays II by jasmine

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.