高分求救:如何实现搜索目录查找需要的文件。

GC80 2004-02-12 11:47:58
以下是我的程序:有问题
就是不能完全实现搜索。
有没有什么好的方法可用?或帮我把下面的bug搞定也不甚感激。

#!/usr/bin/perl -w

use strict;

my $directory = "/tmp/";

OpenSub("$directory");

#recursion open the sub directory
sub OpenSub{

my($dir);
my($file);

my(@lines);
my(@replacelines);

$dir = $_[0];
print "\nCall Opensub($dir)\n";

opendir(DH, $dir) || die "Cannot open $dir: $!";

while ($file = readdir DH){ #read the file name one line
print "\n$dir/$file\n";

if (-f "$dir/$file")
{
print " $file is a File!!\n";
$_ = $file;

if (/.txt$/){
print "$dir/$file is a txt file\n";
if ( open(F, "$dir/$file") ){
@lines = <F>;
print @lines;
close(F);
}
}
else
{
print "$dir/$file is not a txt file\n";
}
}
else
{
$_ = $file;
if (/^\.\.?$/){
print "$dir/$file is a NOT Really Directory!!\n";
}
else
{
print "$dir/$file is a Really Directory!!\n";
OpenSub("$dir/$file");
}

}

}
closedir(DH);
}
...全文
86 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧