檢查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} = <STDIN>); # 取出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); } }
返回
来宾市| 伊吾县| 顺平县| 渭源县| 永清县| 淮安市| 宁都县| 城口县| 石林| 武清区| 保亭| 拉萨市| 姚安县| 大庆市| 韩城市| 眉山市| 海阳市| 镇江市| 台东市| 柳江县| 巨野县| 郴州市| 龙江县| 阿坝县| 铁力市| 恭城| 驻马店市| 临沂市| 晋中市| 美姑县| 绥滨县| 秭归县| 兴安县| 怀仁县| 龙门县| 葫芦岛市| 吉木乃县| 高唐县| 射洪县| 乌拉特中旗| 钟山县|