###########################################################
提供个人自己参考的perl代码片段...
###########################################################
#!/usr/bin/perl -w
use strict;
use LWP::Simple qw(get);
use strict;
use LWP::Simple qw(get);
print $content;
exit 0;
获取网页
获取网页
#!/usr/bin/perl
use strict;
use Net::FTP;
ftp−>login("user","passwd")ordie"Can′tlogin\n",ftp->message;
ftp−>cwd("/pub/FreeBSD/doc/")ordie"Can′tchangedir\n",ftp->message;
ftp−>get("README")ordie"getfailed\n",ftp->message;
$ftp->quit;
exit 0;
FTP下载
exit 0;
FTP下载
#!/usr/bin/perl
use Mail::Sender;
#my mailtext="Dasis\'tderText\ndenichgernesendenwuerde...";mysender = new Mail::Sender {
smtp => 'smtp.163.com',
from => 'zhuzhengju20@163.com',
auth => 'LOGIN',
authid => 'zhuzhengju20',
authpwd => '2000',
on_errors => undef,
} or die "Can't create the Mail::Sender object: Mail::Sender::Error\n";sender->MailFile({to =>'hahazhu0634@126.com',
subject => 'Here is the file',
msg => "I'm sending you the list you wanted.",
file => './name.txt'}) or print Mail::Sender::Error;sender ->Close();
发送带附件的邮件,需要验证,若不需要验证请参考下面的例子!~
[补充知识]
(1)安装Mail::Sender模组
perl -MCPAN -e shell
install Mail::Sender
(2)测试auth参数使用以下命令:
#perl -MMail::Sender -e "Mail::Sender->printAuthProtocols('smtp.sina.com.cn')"
#!/usr/bin/perl
use Mail::Sender;
open(IN, "< ./index.html") or die("");
$sender = new Mail::Sender{
smtp =>'localhost',
from =>'root@localhost'
};
smtp =>'localhost',
from =>'root@localhost'
};
$sender->Open({
to =>'zhuzhengju20@163.com',
subject =>'hello,baby!',
msg =>"please,recive content!",
ctype =>"text/html",
encoding =>"7bit",
});
to =>'zhuzhengju20@163.com',
subject =>'hello,baby!',
msg =>"please,recive content!",
ctype =>"text/html",
encoding =>"7bit",
});
while(<IN>)
{
sender−>SendEx(_);
}
close IN;
$sender->Close();
{
sender−>SendEx(_);
}
close IN;
$sender->Close();
print Mail::Sender::Erroreq""?"sendok!\n":Mail::Sender::Error;
从本地发送HTML的邮件,不需要本地验证(若需验证,请参考上面的例子!~)
从本地发送HTML的邮件,不需要本地验证(若需验证,请参考上面的例子!~)
#!/usr/bin/perl
# fileName: predate
my %mon=(
1 =>"Jan", 2 =>"Feb", 3 =>"Mar", 4 =>"Apr",
5 =>"May", 6 =>"Jun", 7 =>"Jul", 8 =>"Aug",
9 =>"Sep", 10 =>"Oct", 11 =>"Nov", 12 =>"Dec"
);
my (sec1,min,hour,mday,mon,year,wday,yday,isdst)=localtime(time−86400);mon++;
mon=mon{mon};mday = sprintf("%02s",mday);hour = sprintf("%02s",hour);min = sprintf("%02s",min);sec = sprintf("%02s",sec);year+=1900;
print "mday/mon/year\n";print"hour:min:sec\n";
[注意:]
显示昨天的时间,如果将localtime(time-86400)改成localtime(time)那么时间就为今天的时间了
本文转自hahazhu0634 51CTO博客,原文链接:http://blog.51cto.com/5ydycm/166240,如需转载请自行联系原作者