Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Comparing array contents to DB contents

by Gilimanjaro (Hermit)
on Jan 30, 2003 at 13:19 UTC ( [id://231305]=note: print w/replies, xml ) Need Help??


in reply to Comparing array contents to DB contents

By the way; I always prefer accessing my database rows using hashrefs for the records, to ensure I'm accessing the right fields... If you were to use this method, a partial hash comparison would suffise;

my @keylist=qw(field1 field2 field3); for $row (@$list) { $id = hashcmp($row,$vals,@keylist) ? $row->{id} : insert_row($vals) ; } sub hashcmp { my ($a,$b,@keylist) = @_; for(@keylist) { next unless $a->{$_} || $b->{$_}; # both undef return 0 unless String::Approx::amatch($a->{$_},$b->{$_}); } return 1; }
This assumes the named fields are always present in both the $vals and $row hashref...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://231305]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found