I can believe fly.

Wednesday, October 28, 2009

perl温习

1.捕捉外部命令输出结果:反引号``
   即用反引号括起来的任何命令均有perl作为外部命令来运行,就行通过system运行的一样,其输出被捕获,并且作为反引号的返回值返回。如:
   my $svnbakversion = `svnlook youngest $bkrepos1`
   print $svnbakversion;
   如果输出结果不是单字符串,反之是列表,则可将其赋值给数组@dirdata
2. 代码
  if ($svnbakversion =~ /\d+/)
 {
 push (@baksucces, $myrepos);
 }
 else
 {
 push (@bakfailed, $myrepos);
 }
说明: 
a. 检测svnbakversion 是否全为数字
b. push 添加数组元素,即将$myrepos值加入到数组@baksucces/@bakfailed
3. 邮件发送
如果你使用的邮件发送地址,需要验证即使用$smtp->auth('user','pwd');
那么你需要安装Perl模块Authen::SASL (optional Perl module for SVN::Notify)
安装步骤如下:

# wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/Authen-SASL-2.12.tar.gz
# chmod a+x Authen-SASL-2.10.tar.gz
# tar zxvf Authen-SASL-2.10.tar.gz
# cd Authen-SASL-2.10
# perl Makefile.pl
==> Auto-install the 1 optional module(s) from CPAN? [n] y   // 首次执行的时候,需要CPAN 初始化设置。
==> Auto-install the 1 optional module(s) from CPAN? [n] y   //之后一路按回车
# make test
# make install   //安装完成


参考文献: http://opensource.csdn.net/discuss/thread/702

No comments: