《perl常用模块总结.doc》由会员分享,可在线阅读,更多相关《perl常用模块总结.doc(32页珍藏版)》请在金锄头文库上搜索。
1、(1) Net:FTP(2) Net:Telnet(3) LWP:Simple, get()(4) Expect(5) XML:Simple, XMLin()(6) Data:Dumper, Dumper()(7) IO:Socket(8) Date:Manip, DateCalc(), UnixDate()(9) Date:Manip, Date_Cmp()(10) File:Find, find()(11) ExtUtils:Installed, new(), modules(), version()(12) DBI, connect(), prepare(), execute(), fe
2、tchrow_array()(13) Getopt:Std(14) Proc:ProcessTable(15) Shell(16) Time:HiRes, sleep(), time()(17) HTML:LinkExtor, links(), parse_file()(18) Net:Telnet, open(), print(), getline()(19) Compress:Zlib, gzopen(), gzreadline(), gzclose()(20) Net:POP3, login(), list(), get()(21) Term:ANSIColor(22) Date:Cal
3、c Calendar(), Today()(23) Term:Cap, Tgetend(), Tgoto, Tputs()(24) HTTPD:Log:Filter(25) Net:LDAP(26) Net:SMTP mail(), to(), data(), datasend(), auth()(27) MIME:Base64, encode_base64(), decode_base64()(28) Net:IMAP:Simple, login(), mailboxes(), select(), get().(29) Bio:DB:GenBank, Bio:SeqIO(30) Spread
4、sheet:ParseExcel(31) Text:CSV_XS, parse(), fields(), error_input()(32) Benchmark(33) HTTP: Daemon, accept(), get_request().(34) Array:Compare, compare(), full_compare().(35) Algorithm:Diff, diff()(36) List:Util, max(), min(), sum(), maxstr(), minstr().(37) HTML:Parser(38) Mail:Sender(39) Time:HiRes,
5、 gettimeofday(), usleep()(40) Image:Magick(41) Data:SearchReplace(1)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 = RECENT;my $ftp = Net:FTP-new(HOST) or di
6、e Couldnt connect: $n;$ftp-login(anonymous) or die $ftp-message;$ftp-cwd(DIR) or die $ftp-message;$ftp-get(FILE) or die $ftp-message;$ftp-quit;warn File retrieved successfully.n;(2) Net:Telnet#!/usr/bin/perl -w# file:remoteps.pluse strict;use Net:Telnet;use constant HOST = phage.cshl.org;use constan
7、t USER = lstein;use constant PASS = xyzzy;my $telnet=Net:Telnet-new(HOST);$telnet-login(USER,PASS);my lines=$telnet-cmd(ps -ef);print lines;(3) LWP:Simple, get()#!/usr/bin/perl -wuse strict;use LWP:Simple qw(get);my $url = shift | http:/;my $content = get($url);print $content;exit 0;#最简单方便的get网页的方法。
8、(4) Expect#!/usr/bin/perluse 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, params) or die Cant spawn $cmdn;$exp-expect($timeout, -re=Ppassword:);$exp-send_slow($delay, $passrn);$exp-interact(
9、);$exp-hard_close();exit 0;(5) XML:Simple, XMLin()#!/usr/bin/perl -wuse strict;use XML:Simple;my $text = xml;phpnet.php.servletphp*.phpxmlmy $x = XMLin($text);foreach my $tag(keys %$x)my %h = %$x$tag;foreach(keys %h)print $tag = ;print $_ = $h$_n;exit 0;(6) Data:Dumper, Dumper()#!/usr/bin/perl -wuse
10、 strict;use Data:Dumper;print Dumper(INC);print Dumper(%ENV);exit 0;(7) IO:Socket#!/usr/bin/perl -wuse strict;use IO:Socket;my $host = ;my $port = 80;my $http_head = GET / HTTP/1.0nHost: $host:$portnn;my $sock = IO:Socket:INET-new($host:$port)or die Socket() error, Reason : $! n;print $sock $http_he
11、ad;print ;exit 0;(8) Date:Manip, DateCalc(), UnixDate()#!/usr/bin/perluse 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($flagnew();my modules = $inst-modules();foreach(modules)my $ver = $inst-version($_) | ?;printf(%-12s - %sn, $_, $ver);exit 0;(12) DBI, connect(), prepare(), execute(), fetchrow_array()#!/usr/bin/perluse strict;use DBI;my $dbh = DBI-connect(dbi:mysql:dbname, user,passwd, )or die cant connect!n;my $sql = qq/show variables/;my $st