sub open_files {
my @files = @_;
my @lines;
foreach (@files){
print "$_\[1\]\n";
}
foreach my $f (@files){
print "$f\[2\]\n";
open(my $fh,'<',$f) or die " '$f' $!";
print "$fh\[3\]\n";
push(@lines,<$fh>);
close($fh);
}
return @lines;
}
嗨,我打开文件的绝对路径存储在一个数组中存在问题。Glob是不同的值错误打开文件和读取
我想要做的是通过数组并打开每个文件,然后将它们的数据存储在@lines
数组中,然后关闭文件句柄。
但是我能够打开.html
文件中存储的第一个孩子目录.e.g /a/abc.html or /b/bcd.html
但它是不开放(或解析),其在撒哈拉子目录中的文件,如/a/aa/abc.html or /b/bb/bcd.html
我已经把在我的一些额外的print statements
在我的脚本和编号他们的输出为不同的打印行例如[1] [2] [3]
。
这是执行上面的代码的结果:
完整的代码是:pastebin Full code
/mnt/hgfs/PERL/assignment/test/a/aa/1 - Copy - Copy (2).htm[1]
/mnt/hgfs/PERL/assignment/test/a/aa/1 - Copy - Copy (2).htm[2]
GLOB(0x898ad20)[3]
/mnt/hgfs/PERL/assignment/test/b/bb/1 - Copy - Copy (2).htm[1]
/mnt/hgfs/PERL/assignment/test/b/bb/1 - Copy - Copy (2).htm[2]
GLOB(0x898ae40)[3]
/mnt/hgfs/PERL/assignment/test/a/1 - Copy - Copy (2).htm[1]
/mnt/hgfs/PERL/assignment/test/b/1 - Copy - Copy (2).htm[1]
/mnt/hgfs/PERL/assignment/test/c/1 - Copy - Copy (2).htm[1]
/mnt/hgfs/PERL/assignment/test/a/1 - Copy - Copy (2).htm[2]
GLOB(0x898ae40)[3]
/mnt/hgfs/PERL/assignment/test/b/1 - Copy - Copy (2).htm[2]
GLOB(0x898ae40)[3]
/mnt/hgfs/PERL/assignment/test/c/1 - Copy - Copy (2).htm[2]
GLOB(0x898ae40)[3]
如果你们在这里需要完整的代码是:pastebin Full code
错了,我不明白你的问题。预期的产出是什么?它应该是行得通的。你可以看到'[1]'和'[2]'之间永远不会有区别吗? – amon 2013-05-09 13:45:42
它不从这些文件中提取数据 ' /mnt/hgfs/PERL/assignment/test/a/aa/1 - Copy - Copy(2).htm [2] /mnt/hgfs/PERL/(2).htm [2] ' – 2013-05-09 13:46:39