Search code examples
perlunzip

Why do I get a filename of ARRAY(0x7fd5c22f7cd8) when trying to unzip with Perl's Archive::Extract?


I'm using Perl 5.12 on Mac 10.5.7. I have a JAR file, that I wish to unzip, and then process a file matching a file pattern. I'm having trouble figuring out how to iterate over the results of unzipping. I have ...

### build an Archive::Extract object ###
my $ae = Archive::Extract->new( archive => $dbJar );

### what if something went wrong?
my $ok = $ae->extract or die $ae->error;

### files from the archive ###
my @files   = $ae->files;

for (@files) {
    print "file : $_\n";

But there is only one thing returned from the loop -- "ARRAY(0x7fd5c22f7cd8)". I know there are lots of files in the archive, so I'm curious what I"m doing wrong here. - Dave


Solution

  • $ae->files returns an array reference, not an array. Try this:

    my $files = $ae->files;
    
    for(@$files) {
       print "file : $_\n";
    }