作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想将从我的数据库中获取的值存储到散列中。然后,我想比较它们是否具有相同的 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,
},
);
}
最佳答案
以下替换散列中的所有现有值:
%cmhash = (
$material => {
txt => $txt,
price => $price,
},
);
用以下代码替换上面的代码:
$cmhash{$material} = {
txt => $txt,
price => $price,
};
这假设 $material
的值是唯一的。
关于algorithm - 如何将从 SQL 获取的值附加到多个哈希值,然后比较它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48268304/
我是一名优秀的程序员,十分优秀!