首页 > 代码库 > perl package
perl package
#!/usr/bin/perl -w use strict; use File::Basename; use XML::Simple; package CITIC; my $TPMS_EOD_ETC=$ENV{TPMS_EOD_ETC}; #return script name sub getscript_name{ my($path)=@_; my $script_name=File::Basename::basename($path); #( my $pgm = $0 ) =~ s!.*\\(.*)!$1!g ; $script_name =~ s/.pl$|.sql$//; return $script_name; } #return dbh; sub connect_db{ my ($ip,$port,$sid,$user,$pwd)=@_; #CITIC::showtime();print "$ip,$port,$sid,$user,$pwd"."\n"; my $dbh; eval{ $dbh = DBI->connect("DBI:Oracle:host=$ip;port=$port;sid=$sid", $user,$pwd,{AutoCommit=>1,PrintError=>1,RaiseError=>0}); }; #or die "Can‘t connect db,DBI->errstr"; unless ($dbh){ CITIC::showtime();print DBI->errstr."\n"; }else{ CITIC::showtime();print "Connect db success!"."\n"; } return $dbh; } #return dbc info sub get_dbc_info{ my ($subdbc)=@_; my $dbc_file="dbc.xml"; my $xmlfile = "${TPMS_EOD_ETC}${dbc_file}"; my $xml = XML::Simple->new(); my $info = eval{$xml->XMLin($xmlfile,ForceArray => 1)}; my $CONFIGINFO=$info; my %dbc_info; foreach my $get_info(keys(%{$CONFIGINFO->{"config"}->{"$subdbc"}->{"info"}})){ $dbc_info{"user"} = $CONFIGINFO->{"config"}->{"$subdbc"}->{"info"}->{"$get_info"}->{"user"}; $dbc_info{"pwd"} = $CONFIGINFO->{"config"}->{"$subdbc"}->{"info"}->{"$get_info"}->{"pwd"}; $dbc_info{"ip"} = $CONFIGINFO->{"config"}->{"$subdbc"}->{"info"}->{"$get_info"}->{"ip"}; $dbc_info{"port"} = $CONFIGINFO->{"config"}->{"$subdbc"}->{"info"}->{"$get_info"}->{"port"}; $dbc_info{"sid"} = $CONFIGINFO->{"config"}->{"$subdbc"}->{"info"}->{"$get_info"}->{"sid"}; } return %dbc_info; } #去除空格 sub strimstr{ my $str=shift; s/^\s+//; s/\s+$//; return $str; } #return hh:mm:ss yyyymmdd sub showtime{ my($sec,$min,$hour,$day,$mon,$year)=localtime(time()); my $current=""; $sec=sprintf("%02d",$sec); $min=sprintf("%02d",$min); $hour=sprintf("%02d",$hour); $day=sprintf("%02d",$day); $mon=sprintf("%02d",$mon+1); $year+=1900; $current="$hour".":$min".":$sec"." $year"."$mon"."$day"; print "${current} INFO : "; } #return yyyymmdd sub getdate{ my($sec,$min,$hour,$day,$mon,$year)=localtime(time()); my $current=""; $sec=sprintf("%02d",$sec); $min=sprintf("%02d",$min); $hour=sprintf("%02d",$hour); $day=sprintf("%02d",$day); $mon=sprintf("%02d",$mon+1); $year+=1900; $current="$year"."$mon"."$day"; return "${current}"; } #return openfile sub create_logfile($$){ my ($filename,$path)=@_; my $get_date=getdate(); my $get_time=localtime(time()); open(FILE,">","${path}${filename}_${get_date}.log") or die "Can`t Create file :$!"; print FILE "-" x 8 ."[$get_time] Start"."-" x 8 . "\n"; return *FILE; } #close open; sub close_logfile($){ my ($log_file)=@_; my $get_time=localtime(time()); print $log_file "-" x 8 ."[$get_time] End"."-" x 8 . "\n"; close($log_file); } #return true; 1;
perl package
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。