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;
}
嗨,我在打开绝对路径存储在数组中的文件时遇到问题。
我想要做的是遍历数组并打开每个文件,然后将它们的数据存储在@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 完整代码
/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 完整代码