檢查enq1,enq2的type1id的程序
返回
# check_type1id.pl
# 程序目的:檢查一個(gè)type1id下是否有兩個(gè)以上相同的type
use strict;
use DBI;
my(%t,$n,@fld,$pref,@rec,%seen,@uniq,@org,$item);
# 連接數(shù)據(jù)庫
$$pref{dsn} = "DBI:mysql:host=localhost;database=cookbook";
$$pref{dbh} = DBI->connect($$pref{dsn}, "cbuser", "cbpass") or die "Cannot connect to server\n";
$$pref{dbh}->do("SET NAMES utf8");
if(!$$pref{dbh}){
print "SQL read ERROR!\n";
exit;
}
print "Please input table name(enq1,enq2)=";
chop($t{table1} = );
# 取出enq1 or enq2的數(shù)據(jù)
$t{sth} = $$pref{dbh}->prepare("SELECT id,type1id FROM $t{table1}");
$t{sth}->execute;
while ( @rec = $t{sth}->fetchrow_array ) {
push(@{ $t{id_list} },$rec[0]);
push(@{ $t{type1id_list} },$rec[1]);
}
$t{sth}->finish;
# 關(guān)閉數(shù)據(jù)庫
$$pref{dbh}->disconnect;
print "Table name ==> $t{table1}\n";
print " id==> org==>uniq\n";
for $n ( 0 .. $#{ $t{id_list} } ) {
$t{id1} = $t{id_list}[$n];
$t{type1id1} = $t{type1id_list}[$n];
next unless $t{type1id1} =~ /==/;
@org = split(/==/,$t{type1id1});
# 檢查一個(gè)配列中是否有相同的項(xiàng)目
%seen = ();
@uniq = ();
foreach $item (@org) {
push(@uniq,$item) unless $seen{$item}++;
}
if ( $#org != $#uniq ) {
printf ("%04d==>%04d==>%04d\n",$t{id1},$#org,$#uniq);
}
}
返回
锡林郭勒盟|
江西省|
江门市|
汉阴县|
乐陵市|
龙泉市|
洛阳市|
徐闻县|
类乌齐县|
游戏|
庆阳市|
呼图壁县|
交口县|
灵寿县|
班玛县|
黎平县|
罗甸县|
鄂托克前旗|
孝昌县|
辽源市|
东乌珠穆沁旗|
姜堰市|
兴海县|
眉山市|
德化县|
平山县|
永泰县|
西乡县|
徐汇区|
盐池县|
平和县|
邵阳县|
丰宁|
高阳县|
衡东县|
和硕县|
木兰县|
湖北省|
合作市|
行唐县|
长白|