in reply to Parsing Arrays II

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.

Replies are listed 'Best First'.
Re: Re: Parsing Arrays II
by jasmine (Initiate) on Dec 20, 2000 at 10:13 UTC
    Thanks for the help. I'll have a go.
Re: Re: Parsing Arrays II
by jasmine (Initiate) on Dec 20, 2000 at 11:43 UTC
    tried and failed. Though the code is neater it still produces the same results. ie the first value works and the subsequent values don't match. I have printed the values concerned both from db and from array, they appear identical and have no spaces either side. however when compared using eq or exists only the first value returns true