in reply to Comparing array contents to DB contents

Untested, but I think it should work:

foreach $row (@{$list}) { for(my ($i=0, $matched=0; $i<@vals; $i++) { if ( $vals[$i] && $row->[$i+1] && String::Approx::amatch($row->[$i+1], $vals[$i]) ) { $matched++; } else { last; } } return ($matched==@vals) ? $row->[0]; } # none found; do the insert, get the new id and return it

Replies are listed 'Best First'.
Re: Re: Comparing array contents to DB contents
by Gilimanjaro (Hermit) on Jan 30, 2003 at 10:38 UTC
    Or, slower (no short-circuit) but shorter:

    foreach $row (@{$list}) { my @matching = map { String::Approx::amatch($row->[$_+1],$vals[$_]) ? $_ : () } (0..$#vals); return (@matching==@vals) ? $row[0]; } # none found; do the insert, get the new id and return it

    (no check for undef columns here either...)