in reply to Re: Archive::Tar extract
in thread Archive::Tar extract

Thanks Trizen but the problem with your script is that when it uses get_contents it is okay for a normal file but if pdf files or any other special files are involved we cannot just simply open it . I need to extract one file at a time to the specified location perform some matching and then move to the next file which is possible with above script but only on normal text files . So plz help in extracting tem to specified location one by one

Replies are listed 'Best First'.
Re^3: Archive::Tar extract
by trizen (Hermit) on Apr 17, 2012 at 12:24 UTC
    Here we go:
    use strict; use warnings; use Archive::Tar; use File::Spec::Functions qw(catdir); my $input = "libpst.tar.gz"; my $tar = Archive::Tar->new($input); my @files = $tar->list_files; my $output_dir = 'path'; # change this foreach my $file (@files) { my $extracted_file = catdir($output_dir, $file); $tar->extract_file($file, $extracted_file); if ($file =~ /\.txt\z/) { # or whatever open my $fh, '<', $extracted_file or do { warn "$0: Can't open + file $file: $!"; next }; while (defined(my $line = <$fh>)) { # do something with $line } close $fh; } }