opendirDIR,$path;@arr1=readdirDIR;@arr2=grep{-T"$path$_"}@arr1;#textfilesonly@arr3=grep{!-d"$path$_"}@arr1;#nodirectories@arr4=grep{-s"$path$_"<1024}@arr1;#lessthan1K代码解释:假如被测试的目录项是一个文本文件,那么-T文件操作符就会返回真。其实针对目录项的测试操作还有很多。(注:文件和目录在系统中都是以目录项的形式来管理的,所以要区别一个目录项指向的是一个文件还是一个目录需要相应的操作符)。注意上面的readdir函数返回指定目录下的所有目录项。因为在grep函数中对目录项的测试需要文件的完全路径,所以我们把$PATH(存储了目录项的部分路径)和$_(存储了目录项的名字)中的内容联合起来得到文件的完全路径*对目录进行递归搜索*
useFile::Find;find(\&handleFind,'imac:documents:code');subhandleFind{my$foundFile=$File::Find::name;print"$foundFile\n"if($foundFile=~/\.html?$/i);}
openFH,"<anthem";$/=undef;$slurp=;print$slurp;
open(MYOUT,">bottle.txt");*STDOUT=*MYOUT;print"message";
useIO::Tee;$tee=IO::Tee->new(">>debuglog.txt",\*STDOUT);print$tee"anerrorocurredon".scalar(localtime)."\n";
useFile::Basename;$path="/docs/sitecircus.com/html/tricks/trick.of.the.week.html";$basename=basename($path,".html");print$basename;
($uid,$gid)=(getpwnam($username))[2,3]ordie"$usernotinpasswdfile";chown($uid,$gid,$file)orwarn"couldn'tchown$file.";