Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Archive::Zip

Status
Not open for further replies.
Jan 3, 2008
4
US
Ok, trying to use this module to READ a zip file...

But when I use it to read the file I get a hash back describing the file.

This is fine and dandy, but I must be missing something in regards in how to just read a zipped file....

I am using activeperl so I think I am stuck using this module.

Can anyone post a little code snipit on how to actually read a zipped file? Or am I totally miss understanding this module? Do I have to unzipp, read, and then read zip?

Thanks guys.
 
Thanks travis.

I was stuck on that page all day yesterday.

And I feel like I am getting close.

My questions are:

1) Is it possible to use Archive::zip to read a zipped file with out taking separate steps to uncpomress, parse and re-compress?

2)

I have this code:

# Read a Zip file
my $somezip = Archive::Zip->new();
unless ( $somezip->read("$file") == AZ_OK )
{
print "this didn't work!!!!\n";
die 'read error';
}

my $memberName;
foreach my $member ( $somezip->members() )
{
$memberName = $member->fileName();
}

print "$memberName\n";
print Dumper \$somezip;



And the Dumper out put is showing the details of a zipped file in a hash. In the dumped output I can see the un-zipped file name I am trying to parse. But that is where I get stuck.

I keep getting file doesn't exist when I try to apply any other actions on

$membereName

Which displays the name of the un-zipped file I want to process.

Any suggestions?
 
It will read file details with uncompressing but if you want to do something with the file it will need to umcompress it. I don't think it touchs the original though, unless you make changes to the archive then it would have to.

Code:
my $memberName;
    foreach my $member ( $somezip->members() )
    {
        $memberName = $member->fileName();
    }
    
    print "$memberName\n";
needs to be
Code:
    foreach my $member ( $somezip->members() )
    {
        $memberName = $member->fileName();
        print "$memberName\n";
    }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Thanks again for the update.


But I don't really see the difference between what you wrote and what I wrote other than:

you declared the variable inside the foreach loop.

Since I declared it outside I wanted to read the data in the zipped file, then process the data with other functions.

But I just can't seem to get to the actual un-compressed data.

I am know I am probably not asking the right questions. So please forgive me.

Any more advice would be appriciated.
 
my $memberName;
foreach my $member ( $somezip->members() )
{
$memberName = $member->fileName();
#This over write the variable $memberName over and over.
}

#By printing this here instead of in the loop you will only get the last member name
print "$memberName\n";

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top