
Perl
twc829
这个作者很懒,什么都没留下…
展开
-
Term::Cap, Tgetend(), Tgoto, Tputs()
Term::Cap 终端控制模块。代码效果:一个左右移动的字串"welcome to chinaunix! " #!/usr/bin/perl use strict; use Term::Cap; $| = 1; my $i = 1; my $flag = 0; my $tcap = Term::Cap->Tgetent({TERM => undef, OSPEED =>转载 2016-05-24 16:01:17 · 690 阅读 · 0 评论 -
Except
#!/usr/bin/perl use strict; use Expect; my $timeout = 2; my $delay = 1; my $cmd = "ssh"; my @params = qw/202.108.xx.xx -lusername -p22/; my $pass = "passwd"; my $exp = Expect->spawn($cmd,转载 2016-05-19 10:18:52 · 607 阅读 · 0 评论 -
Date::Manip, Date_Cmp()
用于时间日期的比较:#!/usr/bin/perl use strict; use Date::Manip; my $date1 = "Fri Jun 6 18:31:42 GMT 2003"; my $date2 = "2003/05/06"; my $flag=&Date_Cmp($date1,$date2); if($flag<0) { print "dat转载 2016-05-19 10:23:43 · 1031 阅读 · 0 评论 -
XML::Simple, XMLin()
#!/usr/bin/perl -w use strict; use XML::Simple; my $text = <<xml; php net.php.servlet php *.php xml my $x = XMLin($text); foreach my $tag(keys %$x) {转载 2016-05-19 10:20:20 · 499 阅读 · 0 评论 -
Data::Dumper, Dumper()
#!/usr/bin/perl -w use strict; use Data::Dumper; print Dumper(@INC); print Dumper(%ENV); exit 0;转载 2016-05-19 10:21:15 · 361 阅读 · 0 评论 -
IO::Socket
#!/usr/bin/perl -w use strict; use IO::Socket; my $host = "www.chinaunix.net"; my $port = "80"; my $http_head = "GET / HTTP/1.0\nHost: $host:$port\n\n"; my $sock = IO::Socket::INET->new("$host:转载 2016-05-19 10:21:48 · 293 阅读 · 0 评论 -
File::Find, find()
用于在unix文件树结构中查找对象:#!/usr/bin/perl -w use strict; use File::Find; my $file = "access.log"; my $path = "/"; find(&process, $path); sub process{ print $File::Find::dir, "$_\n" if(/$file/); }转载 2016-05-19 10:24:27 · 955 阅读 · 0 评论 -
Date::Manip, DateCalc(), UnixDate()
#!/usr/bin/perl use strict; use Date::Manip; my $date=&DateCalc("today","-1 days", 0);#yesterday my $date=&UnixDate($date, "%Y-%m-%d %T"); print "$date\n"; exit 0;转载 2016-05-19 10:22:42 · 822 阅读 · 0 评论 -
ExtUtils::Installed, new(), modules(), version()
查看已经安装的模块的相应信息。#!/usr/bin/perl use strict; use ExtUtils::Installed; my $inst= ExtUtils::Installed->new(); my @modules = $inst->modules(); foreach(@modules) { my $ver = $inst->versio转载 2016-05-23 15:41:06 · 419 阅读 · 0 评论 -
DBI, connect(), prepare(), execute(), fetchrow_array()
#!/usr/bin/perl use strict; use DBI; my $dbh = DBI->connect("dbi:mysql:dbname", 'user','passwd', '') or die "can't connect!\n"; my $sql = qq/show variables/; my $sth = $dbh->prepare($sql); $st转载 2016-05-23 15:41:38 · 654 阅读 · 0 评论 -
Getopt::Std
命令行参数解析。#!/usr/bin/perl use strict; use Getopt::Std; my %opts; getopts("c:hv", %opts); foreach(keys %opts) { /c/ && print "welcome to ", $opts{$_} || "ChinaUnix", "!\n"; /h/ && print转载 2016-05-23 15:42:18 · 647 阅读 · 0 评论 -
Proc::ProcessTable
直接访问Unix进程表,类似ps命令。#!/usr/bin/perl use strict; use Proc::ProcessTable; my $pt = new Proc::ProcessTable; foreach(reverse sort @{$pt->table}) { print $_->pid, " => "; print $_->cmndline转载 2016-05-23 15:43:22 · 920 阅读 · 0 评论 -
Shell
shell命令直接作为函数,在Perl中调用。#!/usr/bin/perl use strict; use Shell; print "now is : ", date(); print "current time is : ", date("+%T"); my @dirs = ls("-laF"); foreach(@dirs) { print if(//$/);转载 2016-05-23 15:44:59 · 324 阅读 · 0 评论 -
HTML::LinkExtor, links(), parse_file()
#!/usr/bin/perl use strict; use HTML::LinkExtor; my $p = new HTML::LinkExtor; $p->parse_file(*DATA); foreach my $links ($p->links()) { map {print "$_ "} @{$links}; print "\n"; } exit转载 2016-05-23 15:47:09 · 316 阅读 · 0 评论 -
Net::Telnet, open(), print(), getline()
#!/usr/bin/perl use strict; use Net::Telnet; my $p = Net::Telnet->new(); my $h = shift || "www.chinaunix.net"; $p->open(Host => $h, Port => 80); $p->print("GET /\n"); while(my $line = $p->get转载 2016-05-23 15:47:49 · 427 阅读 · 0 评论 -
Compress::Zlib, gzopen(), gzreadline(), gzclose()
直接使用shell的zmore, zless, zcat打开文件也不错,但是如果gz文件很大,还是应该选择zlib。#!/usr/bin/perl use strict; use Compress::Zlib; my $gz = gzopen("a.gz", "rb"); while( $gz->gzreadline(my $line) > 0 ) { chomp $转载 2016-05-23 15:48:37 · 1533 阅读 · 0 评论 -
LWP::Simple, get()
最简单方便的get网页的方法:#!/usr/bin/perl -wuse strict;use LWP::Simple qw(get);my $url = shift || "http://www.chinaunix.net";my $content = get($url);print $content;exit 0;转载 2016-05-19 10:17:33 · 1178 阅读 · 0 评论 -
Net::Telnet
#!/usr/bin/perl -w#file:remoteps.pluse strict;use Net::Telnet;use constant HOST => 'phage.cshl.org';use constant USER => 'lstein';use constant PASS => 'xyzzy';my $telnet=Net::Telnet->new(HOST转载 2016-05-19 10:16:12 · 678 阅读 · 0 评论 -
Net::FTP
#!/usr/bin/perl -w# file: ftp_recent.pl# Figure 6.1: Downloading a single file with Net::FTPuse Net::FTP;use constant HOST => 'ftp.perl.org';use constant DIR => '/pub/CPAN';use constant FILE =转载 2016-05-19 10:14:36 · 1144 阅读 · 0 评论 -
HTTPD::Log::Filter
如果我们工作中经常需要分析Apache日志,这个模块可以提供一些方便。创建对象实例以后,用filter方法来过滤,没有正确匹配的行将返回false,然后用相应的方法print出我们需要的数据。(host,request,date...等等方法,由capture选项以参数引入)可以用re方法打印出作者所使用的匹配模式:use HTTPD::Log::Filter;print HTTP转载 2016-05-24 16:02:32 · 268 阅读 · 0 评论 -
Net::LDAP
LDAP version 3..可以查询基本资料、验证密码。#!/usr/bin/perl use Net::LDAP; ## get a object of ldap $ldap = Net::LDAP->new("1.1.1.1", port =>"389", version => 3) or die "$@"; # object of Net::LDAP::Message $转载 2016-05-24 16:04:09 · 1021 阅读 · 0 评论 -
Net::SMTP mail(), to(), data(), datasend(), auth()
有的SMPT Server需要Authentication,那么就使用auth()方法进行验证。Debug模式打开,可以看到详细的SMTP命令代码。也有助于我们排错。#!/usr/bin/perl use strict; use Net::SMTP; my $smtp = Net::SMTP->new('smtp.sohu.com', Timeout => 10, Debug =转载 2016-05-24 16:04:50 · 1695 阅读 · 0 评论 -
Net::IMAP::Simple, login(), mailboxes(), select(), get()
在取得中文的Folder时,会出现乱码的情况,这个问题现在没有解决。英文的Folder则没问题。 IMAP协议,默认端口为143,可以用telnet登录。telnet imap.xxx.com 1432 login user pass2 list "" *2 select inbox...... #!/usr/bin/perl use strict; use转载 2016-05-24 16:06:25 · 503 阅读 · 0 评论 -
Bio::DB::GenBank, Bio::SeqIO
bioperl(http://bioperl.org/)模块使用--生物信息学中用的模块功能:根据核酸的gi号自动从GenBank中提取FASTA格式的序列,可以多序列提取。#!/usr/bin/perl -w use Bio::DB::GenBank; use Bio::SeqIO; my $gb = new Bio::DB::GenBank; my $seqout = ne转载 2016-05-24 16:07:07 · 1730 阅读 · 0 评论 -
Spreadsheet::ParseExcel
perl解析Excel文件#!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::FmtUnicode; #gb support my $oExcel = new Spreadsheet::ParseExcel; die "You must provide转载 2016-05-24 16:07:59 · 3036 阅读 · 0 评论 -
Text::CSV_XS, parse(), fields(), error_input()
如果field里面也包含分隔符(比如"tom,jack,jeff","rosemike",O'neil,"kurt,korn"),那么我们解析起来确实有点麻烦,Text::CSV_XS挺方便。#!/usr/bin/perl use strict; use Text::CSV_XS; my @columns; my $csv = Text::CSV_XS->new({转载 2016-05-25 13:18:08 · 998 阅读 · 0 评论 -
Benchmark
#!/usr/bin/perl use Benchmark; timethese(100, { 'local'=>q { for(1..10000) { local $a=$_; $a *= 2;转载 2016-05-25 13:19:23 · 763 阅读 · 0 评论 -
HTTP::Daemon, accept(), get_request(), send_file_response()
一个简单的,只能处理单一请求的Web服务器模型。send_file_response()方法能把Client请求的文件传送过去。#!/usr/bin/perl use HTTP:: Daemon; $| = 1; my $wwwroot = "/home/doc/"; my $d = HTTP:: Daemon->new || die; print "Perl Web-Ser转载 2016-05-25 13:20:12 · 508 阅读 · 0 评论 -
Array::Compare, compare(), full_compare()
用于数组比较。本例实现类似shellcommand - diff的功能。如果我们要比较的不是文件,而是比如系统信息,远程文件列表,数据库内容变化等,这个模块会给我们提供方便灵活的操作。#!/usr/bin/perl use Array::Compare; $comp = Array::Compare->new(WhiteSpace => 1); $cmd = "top -n1转载 2016-05-25 13:20:50 · 784 阅读 · 0 评论 -
Algorithm::Diff, diff()
用于文件比较。实现类似unixcommand diff的功能。 #!/usr/bin/perl use Algorithm::Diff qw(diff); die("Usage: $0 file1 file2\n") if @ARGV != 2; my ($file1, $file2) = @ARGV; -T $file1 or die("$file1: binary\n")转载 2016-05-25 13:21:20 · 446 阅读 · 0 评论 -
List::Util, max(), min(), sum(), maxstr(), minstr()...
列表实用工具集。#!/usr/bin/perl use List::Util qw/max min sum maxstr minstr shuffle/; @s = ('hello', 'ok', 'china', 'unix'); print max 1..10; #10print min 1..10; #1print sum 1..10; #55p转载 2016-05-25 13:21:59 · 1133 阅读 · 0 评论 -
HTML::Parser
解析HTML。本例为找出一个html文本中的所有图片的地址。(即IMG标签中的src)子程序start中的“$tag =~ /^img$/”为过滤出img标签。如果换为“$tag =~/^a$/”,即是找出所有的链接地址。#!/usr/bin/perl use LWP::Simple; use HTML::Parser; my $url = shift || "http://转载 2016-05-25 13:22:58 · 294 阅读 · 0 评论 -
Mail::Sender
1 发送附件#!/usr/bin/perl use Mail::Sender; $sender = new Mail::Sender{ smtp => 'localhost', from => 'xxx@localhost' }; $sender->转载 2016-05-25 13:58:20 · 1220 阅读 · 0 评论 -
网络工程师需要掌握的10个有用的Perl模块
Perl综合典藏网CPAN有很多现成的Perl模块,能够让开发人员高效完成常用任务;CPAN在网络编程上提供数千个模块,从一般的(服务器守护程序)到针对性非常强的应用程序(如与思科路由器进行交互的程序)。1 Net::Server该模块提供的例程可创建一个全功能的服务器,它可作为单连接服务器运行,也可通过*NIX的inetd守护程序运行;支持很多服务器特性,如TCP、UDP转载 2016-05-19 09:49:48 · 650 阅读 · 0 评论 -
Net::POP3, login(), list(), get()
telnet pop3.web.com 110 也可以直接连到pop3 server上,然后通过pop3命令与邮件服务器交互,简单的命令有:USER namePASS stringSTATLIST [n]RETR msgDELE msgNOOPRSETQUIT可以利用Net::Telnet来做一个收信件的简单程序。#!/usr/bin/perl u转载 2016-05-23 15:50:17 · 810 阅读 · 0 评论