Perl 模块
1.? File::Find 模块 use File::Find???? 使用该模块,这时一个find的新函数就可以使用了 find? subref,dirlis????? find的第二个参数是要搜索的目录。第一个参数是子例程引用。 $File::Find::name?? 当前路径名,包括目录和文件名 $File::Find:dir??????? 当前目录名 #! /usr/bin/perl -w?????????? 这是一个删除/tmp目录下文件的脚本 ====================== #! /usr/bin/perl -w use strict; use File::Find; sub wanted{ ????? if (-f $File::Find::name) { ???????????? if ($File::Find::name =~ /.tmp$/i) { ?????????????????? print "Remove $File::Find::namen"; ?????????????????? unlink $File::Find::name; ????????????? } ??????? } } find(&;wanted,'c:/','d:/'); ===?============================= 2.File::Copy 模块 use File::Copy; copy("sourcefile","destination") || warn "Could not copy file: $!"; #! /usr/bin/perl -w ===================== File::Copy模块也提供了一个move函数。将一个文件从一个目录移到另外一个目录里。 #! /usr/bin/perl -w ====================== #! /usr/bin/perl -w use File::Copy; if (not move("import.doc" "d:/archives/import.doc")) { ???????? warn "import.doc could not e moved: $!"; ???????? unlink "d:/archives/import.doc"; } ?================================= 3. Net::Ping? 模块 use Net::Ping?? Net::Ping模块提供了一个pingecho函数,该函数有两个参数,第一个参数是要查找的主机,第二个参数是指明pingecho应该等待多长时间才能收到对方应答,以秒为单位 #! /usr/bin/perl -w =================== #! /usr/bin/perl -w ================================ use Net::Ping; =================================== 4.Net::FTP 模块 use Net::FTP; ? #! /usr/bin/perl use Net::FTP $ftp=Net::FTP->new("192.168.1.1",Debug=>0) or die "Cannot connect FTP"; $ftp->login('username','password') or die "Can not login",$ftp->message; $ftp->cwd("/var/pub/") or die "Can not change working directory"? #切换FTP的工作目录 chdir "/home/linux";???? #更改本地目录(用于接收文件) $ftp->get("passwd") or die "get failed",$ftp->message;??? #获取指定文件 $ftp->quit;?????? #退出
?
?
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |