perl中的几个模块使用.

perl中的几个模块使用.,第1张

概述perlCPAN模块DBI.DBD::Mysql my $db_host = "localhost";   my $db_port = "3306";   my $db_user = "root";   my $db_pass = "redhat";   my $db_name = "test";   my $dsn = "DB perlCPAN模块DBI.DBD::MysqL
   my $db_host = "localhost"     my $db_port = "3306"     my $db_user = "root"     my $db_pass = "redhat"     my $db_name = "test"     my $dsn = "DBI:MysqL:$db_name:$db_host:$db_port"     my $dbh = DBI->connect($dsn,$db_user,$db_pass,{raiseerror => 0,PrintError => 0}) or return ("0");         $dbh->do("set names gbk");     #   my $sth = $dbh->prepare("select * from MysqL.user");     #      $sth->execute();     #               while(my @row = $sth->fetchrow_array){                     #       print "@row\n"     #   }             $sth = $dbh->prepare("SHOW SLAVE STATUS");             $sth->execute();                     while(my $hash=$sth->fetchrow_hashref){                             my $iostate = $hash->{'Slave_IO_Running'};                             my $sqlstate = $hash->{'Slave_sql_Running'};     #       print "$iostate\n$sqlstate\n"                                    if ($iostate eq 'No' || $sqlstate eq 'No'){                                             warn "MysqL Slave database down..\n"        }       }   

 

perl标准模块Net::Ping和IO::Socket

  #!/usr/bin/perl     use warnings;     use strict;     use IO::Socket;     use Net::Ping;     my $host = "192.168.1.2"    my $port = "80"    my $p=Net::Ping->new("icmp");     $p->Ping($host,5) ? print "$host: runing\n" : print "$host: down\n"    my $sock = IO::Socket::INET->new(                             Timeout => 4,                             PeerAddr => $host,                             Peerport => $port,                             Proto   => "tcp"    );     $sock ? print "$port: Listening\n" : print "$port: faild\n"  
perl标准模块中file::Find的使用方法.
  #!/usr/bin/perl     use warnings;     use strict;     use file::Find;     my $path="/etc/"    sub wanted{             my $file=$file::Find::name            if(-f $file and -s $file > 5000 and -s $file < 10000){             if($file =~m/\.conf$/){             print "$file\n"      }      }         find(\&wanted,$path);   

perl标准模块Net::SMTP和依赖CPAN模块Net::SMTP_auth认证模块.

  #!/usr/bin/perl     use warnings;     #use strict;     use Net::SMTP;     use Net::SMTP_auth;     my $smtp_mail_host = 'smtp.sinanet.com'    my $mail_user_from = 'donghui@leju.sina.com.cn'    my $mail_user_to = 'donghui@leju.sina.com.cn'    my $mail_user_pass = "P@ssW0rd"    my $mail_helo = 'mail.sinanet.com'    $smtp = Net::SMTP->new(                     Host => "$smtp_mail_host"                    Hello => "$mail_helo"                    Timeout => 40,                     DeBUG => 1,     or dIE "can not connect mail server\n"    $smtp->auth("$mail_user_from","$mail_user_pass"or dIE "auth Failed!\n"    $smtp->mail("$mail_user_from");     $smtp->to("$mail_user_to");     $smtp->data();     $smtp->datasend("mail test!!\n");     $smtp->datasend("donghui\n");     $smtp->dataend();     $smtp->quit();   
perl中远程执行命令CPAN模块:Expect
  #!/usr/bin/perl     use warnings;     use strict;     use Expect;     my $host = "192.168.1.2"    my $pass = "redhat"     $ENV{'TERM'} = "xterm"    my $exp = Expect->new;        $exp->log_stdout(0);        $exp = Expect->spawn("ssh -l root $host"or dIE "can't conenct $host\n"       $exp->log_file("ssh_host.log","w");        $exp->expect(3,[qr/connecting \(yes\/no\)/i,                             sub{                                     my $self = shift;                                     $self->send("yes\n");                                     exp_continue;      }],                 qr/password:/i,             sub{                     my $self = shift;                     $self->send("$pass\n");                     exp_continue;      }]     );     $exp->send("netstat -ntpl\n") if ($exp->expect(undef,'#'));     $exp->send("exit\n") if($exp->expect(undef,'#'));     $exp->log_file(undef);   
总结

以上是内存溢出为你收集整理的perl中的几个模块使用.全部内容,希望文章能够帮你解决perl中的几个模块使用.所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1287320.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-09
下一篇2022-06-09

发表评论
请登录后评论...
登录
后才能评论 提交

评论列表(0条)
    保存
    {label}