[prev in list] [next in list] [prev in thread] [next in thread]
List: perl-win32-users
Subject: RE: problem comparing hashes
From: Burak_Gürsoy <burakgursoy () gmx ! net>
Date: 2002-12-26 21:09:40
[Download RAW message or body]
#!/perl -w
use strict;
my %default = (
one => 1,
two => 2,
three => 3,
four => 4,
five => 5,
six => 6,
);
my %cgi = (
one => 10,
two => 20,
three => 3,
four => 4,
five => 5,
six => 6,
);
my %extra;
foreach my $key (keys %default) {
$extra{$key} = $cgi{$key}
if(exists $cgi{$key} and $cgi{$key} ne $default{$key});
}
print "DEBUG:\nChanged keys are:\n";
foreach (sort keys %extra) {
print "$_ => $extra{$_}\n";
}
__END__;
-----Original Message-----
From: perl-win32-users-admin@listserv.ActiveState.com
[mailto:perl-win32-users-admin@listserv.ActiveState.com]On Behalf Of Adam
Peterson
Sent: Thursday, December 26, 2002 10:33 PM
To: perl-win32-users@listserv.ActiveState.com
Subject: problem comparing hashes
hi,
i have a cgi script where i attempt to compare the values in 2 separate
hashes( %query_data & %cgi_data). if there are differences in the vaules,
i would like to build a 3rd hash (%update_data) containing the differences
(the keys of the two hashes are the same). i'm having no luck... any
advice?
thanks
excerpt from code:
if (@inserts)
{
#### build hash from cgi/user input
foreach my $insert (@inserts)
{
push (@{$cgi_data{$insert}}, $wrkd[$count], $cmt[$count],
$crash[$count]);
$count++;
}
#### compare cgi and query hashes. if there are differences, build a new
update hash
foreach my $kee (keys (%query_data))
{
foreach my $keyz (keys (%cgi_data))
{
unless (${query_data{$kee}[0]} eq ${cgi_data{$keyz}[0]} &&
${query_data{$kee}[1]} eq ${cgi_data{$keyz}[1]} && ${query_data{$kee}[2]}
eq ${cgi_data{$keyz}[2]})
{
push ( @{$update_data{$keyz}}, ${cgi_data{$keyz}[0]},
${cgi_data{$keyz}[1]}, ${cgi_data{$keyz}[2]} );
last;
}
}
}
#### insert data from update hash into db
foreach my $up (keys (%update_data))
{
$sth = $dbh->prepare("
use eggsupp
update filesupp set status = '${update_data{$up}[0]}', comment =
'${update_data{$up}[1]}', crashtype = '${update_data{$up}[2]}'
where filename = '$up'
");
$sth->execute;
my $rows_affected = $sth->execute();
my %updates = (file => $up, rows => $rows_affected);
push (@list2, \%updates);
}
$tmpl_up->param({updates=>\@list2});
print $cgi->header("text/html"), $tmpl_up->output;
exit;
}
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic