【发布时间】:2010-07-27 22:12:53
【问题描述】:
在下面的代码中有一个散列,其中包含具有 name、pid、type 和 time1 等字段的记录。
pid 和 name 是包含重复项的重复字段。
我发现更新需要修改的字段
否则插入,这里name 和pid 有重复项(重复字段)。
其余的都是独一无二的。在创建表Serial no 时,我还有一个独特的字段。我应该怎么继续?我只在这段代码中做了一个插入。我不知道如何使用 Perl 将检索到的记录存储到数组中。请指导我。
for my $test11 (sort keys %seen) {
my $test1 = $seen{$test11}{'name'};
my $test2 = $seen{$test11}{'pid'};
my $test3 = $seen{$test11}{'type'};
my $test4 = $seen{$test11}{'time1'};
print "$test11\t$test1$test2$test3$test4\n";
$db_handle = &getdb_handle;
$sth = $dbh->prepare("Select username,pid,sno from svn_log1");
$sth->execute() or die "SQL Error: $DBI::errstr\n";
my $ref = $sth->fetchall_arrayref();
print "hai";
print "****$ref";
$sth = $dbh->prepare("INSERT INTO svn_log1 values('$sno','$test11','$test1','$test4','$test2','$test3')");
$sth->execute() or die "SQL Error: $DBI::errstr\n";
}
【问题讨论】:
-
对不起,你必须更清楚你在问什么。您的代码示例似乎遍历了 %seen 中的所有记录,并为 每条记录 从数据库中获取整个表,然后再向其中添加一条记录。这对我来说毫无意义。我知道您想捕获重复项并对它们做一些不同的事情,最好通过另一个哈希来完成,将可能重复的值作为键;但我看不清楚你想做什么来给你答案。