我希望递归读取一个目录,在HTML页面使用Template::Toolkit打印数据结构。 但是,我不知道该如何以可读的形式保存路径和文件。
我的想法是这样的:
sub list_dirs{
my ($rootPath) = @_;
my (@paths);
$rootPath .= '/' if($rootPath !~ /\/$/);
for my $eachFile (glob($path.'*'))
{
if(-d $eachFile)
{
push (@paths, $eachFile);
&list_dirs($eachFile);
}
else
{
push (@files, $eachFile);
}
}
return @paths;
}
我该如何解决这个问题?