gpt4 book ai didi

algorithm - 如何将从 SQL 获取的值附加到多个哈希值,然后比较它们

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:41:53 25 4
gpt4 key购买 nike

我想将从我的数据库中获取的值存储到散列中。然后,我想比较它们是否具有相同的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com