在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
printf"write the path you want to search files:"; $searchdir=<STDIN>; chomp $searchdir; printf "Input search string:"; $searchstr=<STDIN>; chomp $searchstr; opendir(DIRHANDLE,$searchdir) || die "Cann't open $searchdir !"; while($file=readdir DIRHANDLE) { if (-d "$searchdir/$file") { printf "$searchdir/$file is a directory!\n"; } else { open(FileHandle, "$searchdir/$file") || die "cann't open $searchdir/$file !\n"; $lines=1; while (defined($line=<FileHandle>)) { $back=index($line,$searchstr); if ( $back != -1 ) { print"$file:$lines:$line"; } $lines=$lines+1; } } close(FileHandle); } closedir(DIRHANDLE); |
请发表评论