v-lhb-db01:/root/sbin# cat s1.pl
use Net::SMTP;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
sub send_mail{
if (@_ != 2){print "请输入2个参数\n";exit 1};
my $CurrTime = time2iso(time());
my $to_address = shift;
my $mail_user = 'zhao.yangjian@163.com';
my $mail_pwd = 'zhaoyangjian724';
my $mail_server = 'smtp.163.com';
my $from = "From: $mail_user\n";
my $subject = "Subject: zjcap info\n";
my $info = "$CurrTime--$mess_info";
my $message = <<CONTENT;
$info
CONTENT
my $smtp = Net::SMTP->new($mail_server);
$smtp->auth($mail_user, $mail_pwd) || die "Auth Error! $!";
$smtp->mail($mail_user);
$smtp->to($to_address);
$smtp->data(); # begin the data
$smtp->datasend($from); # set user
$smtp->datasend($subject); # set subject
$smtp->datasend("\n\n");
$smtp->datasend("$message\n"); # set content
$smtp->dataend();
$smtp->quit();
};
send_mail;
v-lhb-db01:/root/sbin# perl s1.pl
请输入2个参数
---------------------------------------------------------------------
v-lhb-db01:/root/sbin# perl s1.pl
请输入2个参数
Auth Error! No such file or directory at s1.pl line 19.
v-lhb-db01:/root/sbin# cat s1.pl
use Net::SMTP;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
sub send_mail{
if (@_ != 2){print "请输入2个参数\n"};
my $CurrTime = time2iso(time());
my $to_address = shift;
my $mail_user = 'zhao.yangjian@163.com';
my $mail_pwd = 'zhaoyangjian724';
my $mail_server = 'smtp.163.com';
my $from = "From: $mail_user\n";
my $subject = "Subject: zjcap info\n";
my $info = "$CurrTime--$mess_info";
my $message = <<CONTENT;
$info
CONTENT
my $smtp = Net::SMTP->new($mail_server);
$smtp->auth($mail_user, $mail_pwd) || die "Auth Error! $!";
$smtp->mail($mail_user);
$smtp->to($to_address);
$smtp->data(); # begin the data
$smtp->datasend($from); # set user
$smtp->datasend($subject); # set subject
$smtp->datasend("\n\n");
$smtp->datasend("$message\n"); # set content
$smtp->dataend();
$smtp->quit();
};
send_mail;
v-lhb-db01:/root/sbin# perl s1.pl
请输入2个参数
Auth Error! No such file or directory at s1.pl line 19.
此时程序没退出,继续运行了
perl 子程序传递参数
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
如何监控子程序的运行参数 如何验证子程序功能
总体问题 · 创建子程序的理由充分吗? · 如果把一个子程序中的某些部分独立成另一个子程序会更好的话,你这样做了吗? · 是否用了明
如何监控子程序的运行参数 编程 防火墙 工作 任务