perl 子程序传递参数
2015-05-11 16:56
302 查看
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 子程序传递参数不同类型变量 设置
- perl 函数参数传递与返回值(一)
- perl基础:传递hash类型参数
- PERL语言入门:第四章:子程序(函数):参数与子程序的私有变量
- Perl函数参数中传递数组和引用的使用
- Perl函数参数中传递数组和引用的使用
- Perl子程序参数是数组或哈希表时的问题
- GWA2-Perl的面向对象方法中数组或哈希列表参数传递问题
- perl 函数参数中传递数组和引用的一些问题
- perl参数传递的三种方法
- perl基础:传递hash类型参数
- Perl脚本间传递参数
- perl 函数参数中传递数组和引用的一些问题
- perl 传递数组作为参数
- perl 参数传递
- Perl脚本间传递参数 (二)
- Perl脚本间传递参数
- 1214 子程序参数传递
- perl中子程序中参数的两种引用(传递)方式介绍
- Oracle 指定子程序 OUT 或 IN OUT 参数为引用传递