Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在perl中读取gzip和tar文件_Perl_Perl Module - Fatal编程技术网

如何在perl中读取gzip和tar文件

如何在perl中读取gzip和tar文件,perl,perl-module,Perl,Perl Module,我已将文本文件“FilenameKeyword.txt”文件放在E:/Test文件夹中,在我的perl脚本中,我试图遍历该文件夹,并试图找到一个文件名为的文件,其中包含字符串“Keyword”,之后我已在脚本中打印了该文件的内容。 现在我希望对放置在压缩的tar文件中的文件执行相同的操作 我试图从中提取详细信息的假设文件: E:\test.tar.gz 想知道在perl中是否有可能在不解压缩假设文件的情况下搜索和读取该文件。如果不可能,我还将分配一些临时内存来解压缩该文件,在从特定文本文件提取内

我已将文本文件“FilenameKeyword.txt”文件放在E:/Test文件夹中,在我的perl脚本中,我试图遍历该文件夹,并试图找到一个文件名为的文件,其中包含字符串“Keyword”,之后我已在脚本中打印了该文件的内容。 现在我希望对放置在压缩的tar文件中的文件执行相同的操作

我试图从中提取详细信息的假设文件: E:\test.tar.gz

想知道在perl中是否有可能在不解压缩假设文件的情况下搜索和读取该文件。如果不可能,我还将分配一些临时内存来解压缩该文件,在从特定文本文件提取内容后应将其删除

在互联网上搜索时,我可以使用Archive::extract来提取和读取gzip/tar文件,这是Perl的新手,我真的不知道应该如何使用它。你能帮个忙吗

输入文件:FilenameKeyword.txt

脚本:

use warnings;
use strict;

my @dirs = ("E:\\Test\\");
my %seen;
while (my $pwd = shift @dirs) {
        opendir(DIR,"$pwd") or die "Cannot open $pwd\n";
        my @files = readdir(DIR);
        closedir(DIR);
        foreach my $file (@files) 
        {
                if (-d $file and ($file !~ /^\.\.?$/) and !$seen{$file}) 
                {
                        $seen{$file} = 1;
                        push @dirs, "$pwd/$file";
                }
                next if ($file !~ /Keyword/i);
                my $mtime = (stat("$pwd/$file"))[9];
                print "$pwd$file";
                print "\n";
                open (MYFILE, "$pwd$file");
                while (my $line = <MYFILE>){
                #print $line;
                my ($date) = split(/,/,$line,2);
                if ($line =~ s!<messageText>(.+?)</messageText>!!is){
                print "$1";
                }
                }

        }
}
正在寻找帮助以检索放置在下的文件的内容 E:\test.tar.gz

期望输出:

E:\test.tar.gz\FilenameKeyword.txt
1311 messages Picked from the Queue. 

我一直在使用CPAN模块,CPAN模块不适用于我,因为我在同一台机器上安装了oracle 10g enterprise edition,由于某些软件冲突活动状态,perl无法编译并引用CPAN模块的perl库,我已在我的机器上卸载了oracle以使其正常工作

#!/usr/local/bin/perl
use Archive::Tar;
my $tar = Archive::Tar->new;
$tar->read("test.tar.gz");
$tar->extract();

如果您的文件仅为gzip文件,则可以按照概述的“流式”方式读取其内容。本文演示了一种使用open和fork打开和解压缩文件的技术,然后将其提供给Perl的while(),允许您对其进行迭代


因为tar基本上是连接东西的,所以可以根据您的场景调整它。

快速搜索“perl-tar-gzip”就会得到结果。看起来这个模块正是你想要的。虽然措辞拙劣,但实际上似乎提出了一个解决方案。它也是迄今为止唯一尝试过的解决方案,因此删除它将完全没有答案。
#!/usr/local/bin/perl
use Archive::Tar;
my $tar = Archive::Tar->new;
$tar->read("test.tar.gz");
$tar->extract();