perl模拟windows的查找 |
|
#!usr/bin/perl
if ( $#ARGV<2 ) { print<<"EOF"; 输入参数不够,您输入的格式应该是: perl $0 要搜索的字符串 搜索文件列表 记录文件 EOF exit 0; } $string=shift; $logfile=pop; while(<>){ print "现在处理文件 $ARGV ... n" if ($currentFile ne $ARGV); chomp($_); foreach $word(split(/ /,$_)){ $couter++ if ($word eq $string); } $currentFile=$ARGV; } print "$string 出现的总次数是: $couter "; open(FILE,">>$logfile"); print FILE "#"x30,"n"; print FILE "$string 出现的总次数是: $couter "; close FILE; |