我想将从数据库中获取的值存储到哈希中。然后,我想比较并查看它们是否具有相同的material
。如果它们具有相同的material
,我想比较txt
。如果txt
不同,我想使用storedisp。如果文本相同,我想使用coursemat:
my $stmt1 = qq(select txt, price, material from coursemat);
my $sth1 = $pagev->runQ($stmt1); #run query in house function
my $stmt2 = qq(select material from storedisp);
my $sth2 = $pagev->runQ($stmt2);
while(my ($txt, $price, $material) = $sth->fetchrow_array) {
%cmhash = (
$material => {
txt => $txt,
price => $price,
},
);
}
while(my $txt = $sth->fetchrow) {
%sdhash = (
$material => {
txt => $txt,
},
);
}
答案 0 :(得分:3)
The following replaces all existing values in the hash:
%cmhash = (
$material => {
txt => $txt,
price => $price,
},
);
Replace the above code with the following:
$cmhash{$material} = {
txt => $txt,
price => $price,
};
This assumes the values of $material
are unique.