加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl数据库连接操作

发布时间:2020-12-16 00:13:33 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/perl use strict; use warnings; use DBI; opendir (DIR,"dirpath/") ||die "can not open it"; my @connect = readdir(DIR); closedir DIR; my $dir_need; foreach my $con (sort @connect){ ? ? if ($con =~ /-[0-9]{2}-[0-9]{2}_/){ ? ? ? ? $
#!/usr/bin/perl use strict; use warnings; use DBI; opendir (DIR,"dirpath/") ||die "can not open it"; my @connect = readdir(DIR); closedir DIR; my $dir_need; foreach my $con (sort @connect){ ? ? if ($con =~ /-[0-9]{2}-[0-9]{2}_/){ ? ? ? ? $dir_need = $con; ? ? } } my $database = "DBI:mysql:database"; my $username = "root"; my $password = "password"; my $mysql_dbh = DBI->connect($database,$username,$password )|| die "Database connection not made: $DBI::errstr"; my $count; my @type = qw[stf utf merged]; for($count =0;$count<3;$count++) { open (PYTHON,"/dirpath/$dir_need/$type[$count]/python/index.html") || die "can not open it"; my @connect = <PYTHON>; close PYTHON; my $flag = 0; my $data_hash ; my $file_name ; my @name_arr = qw[statements run excluded branches br_exec coverage]; my @key_name; my $index = 0; foreach my $eachline (@connect){ ? ? chomp $eachline; if($eachline =~ /<td class='name left'><.*?>(.*?)<//) { ? ?$flag = 1; $file_name = $1; push(@key_name,$1); } elsif($eachline =~ /<td>([0-9]+)</td>/ && $flag) { ? ?$data_hash->{$file_name}->{$name_arr[$index++]} = $1; } elsif($eachline =~ /<td class='right'>(.*)%</td>/ && $flag) { ? ?$data_hash->{$file_name}->{$name_arr[$index]} = $1; $index = 0; $flag = 0; } } foreach my $key (@key_name) { ? ? my $sql ="insert into python_coverage (builds_time,framework,file,statements,run,excluded,branches,br_exec,coverage) ? ? ? ? ? ? ? ? ? ?values (?,?,?)"; my $sth = $mysql_dbh->prepare($sql); ? ? ?$sth->bind_param(1,$dir_need); ? ? if($count == 2) {$sth->bind_param(2,"all"); } ? ? else { $sth->bind_param(2,$type[$count]); } ? $sth->bind_param(3,$key); ? ? my $para_index = 4; ? ? for($index =0;$index <6;$index++) { $sth->bind_param($para_index,$data_hash->{$key}->{$name_arr[$index]}); $para_index++; } $sth->execute(); }? }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读