http://www.perlmonks.org?node_id=875087


in reply to How to match elements of array

You have already got a better approach from PeterPeiGuo but if you are curious about what's wrong in your code, here are a few things which I noticed

  1. You are not comparing the names, rather you are comparing the existence of names in db and in the array.if(($row->{image_name_1} ne "") eq ($pics[0] ne "")) will increment $flag_pic even if $row->{image_name_1} is "xyz" and $pics[0] is "abc"
  2. (Let us assume previous error is corrected) You are assuming the order to be same in db and in array. If name in first row of db matches with that of second element in the array, it will go unnoticed and you will fire an "insert" query.

You definitely need to modify the approach

Replies are listed 'Best First'.
Re^2: How to match elements of array
by Anonymous Monk on Dec 03, 2010 at 12:01 UTC
    I am not trying to increment anything, I am trying to assignment a value so it can be true down on the IF statement if the element of the array "@pics" will match or be the same as the one found in the database.