toadi has asked for the wisdom of the Perl Monks concerning the following question:

It seems I can't extract tar.gz files with that module.
Of course I can use system with gunzip bit I wanted to do it this way.
For Archive module I use version 0.22
The error message for this snippet is :
Can't use an undefined value as an ARRAY reference at /usr/lib/perl5/s +ite_perl/5.005/Archive/Tar.pm line 736.
The code snippet:
use strict; use Archive::Tar; my ($dirname,$file); $dirname = "path_to_dir"; opendir(DIR,$dirname) or die "unable to open $dirname : $|"; while(defined($file = readdir(DIR))){ my $tar = Archive::Tar->new(); $tar->read("$file", 1); my @tar_files = $tar->list_files(); $tar->extract(@tar_files); } closedir(DIR);

My opinions may have changed,
but not the fact that I am right

Replies are listed 'Best First'.
Re: Archive::Tar
by japhy (Canon) on Nov 21, 2000 at 18:32 UTC
    readdir() returns the file NAME, not the relative path to the file. You need to prepend $dirname/ to the file when you create the Archive::Tar object.

    japhy -- Perl and Regex Hacker
Re: Archive::Tar
by btrott (Parson) on Nov 21, 2000 at 23:35 UTC
    This isn't really related to your problem (which I see you've solved now), but if you're going to be extracting *all* of the files in the archive (which you are, in the example above), you can just use the extract_archive class method:
    Archive::Tar->extract_archive("$dirname/$file");
    The extracted files will be placed under the current working directory. Archive::Tar will automatically detect when it's dealing with a compressed archive.
Re: Archive::Tar
by toadi (Chaplain) on Nov 21, 2000 at 19:11 UTC
    Ok,ok

    I was to fast ... The files aren't tar files, but just gzip files.... That was the prob, I just proceed with the system command.
    I would appreciate if someone knows how I can gunzip without the system?

    --
    My opinions may have changed,
    but not the fact that I am right

      Check out the Compress::Zlib module.