CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Archive::Zip Usage



Oct 7, 2002, 2:51 PM

Post #1 of 8 (2541 views)
Archive::Zip Usage Can't Post

Hi, I'm wondering of anyone can give me some pointers on the usage of Archive::Zip. I've looked at the examples and docs, but not one aspect of it will work for me. I must be doing something wrong. I am trying to extract a text file from a zip file, retrieve the contents of the text file, then use that text in the script. At the moment I'm using code as follows:

$url =
$filepath =

("$ext" eq "zip") {
my $dirName =
use Archive::Zip;
my $zip = Archive::Zip->new();
my $status = $zip->read( $filepath );
if (
"$status" eq "AZ_OK") {
my $status = $zip->extractMemberWithoutPaths( $cfdescfile );
if (
"$status" eq "AZ_OK") {
$cfdescpath =
$fsize = (-s $cfdescpath);

This recognizes the file as a zip but fails to do anything to it. It outputs no error messages. I find the docs for this package woefully inadequate. It looks like I'm basically gonna hafta just play with syntax after syntax till I stumble upon the right combo. Does anyone know of an easier way to do this?


Oct 8, 2002, 1:03 AM

Post #2 of 8 (2532 views)
Re: [Mordred] Archive::Zip Usage [In reply to] Can't Post

Where did you get

("$status" eq "AZ_OK")


Did you know that AZ_OK is a subroutine ?
You should read the documentation again,
and pay close attention to detail
( "eq" is never used anywhere )


Many of the methods in Archive::Zip return error codes. These are implemented as inline subroutines, using the use constant pragma. They can be imported into your namespace using the :CONSTANT tag:

use Archive::Zip qw( :CONSTANTS );
die "whoops!" if $zip->read( '' ) != AZ_OK;
AZ_OK (0)

Everything is fine.


The read stream (or central directory) ended normally.


There was some generic kind of error.


There is a format error in a ZIP file being read.


There was an IO error.

Thaumaturge / Moderator

Oct 8, 2002, 1:07 AM

Post #3 of 8 (2533 views)
Re: [Mordred] Archive::Zip Usage [In reply to] Can't Post

I haven't used Archive::Zip but I notice that the author has written a FAQ which may be of use to you.

Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks


Oct 8, 2002, 2:54 AM

Post #4 of 8 (2529 views)
Re: [thebitch] Archive::Zip Usage [In reply to] Can't Post

Gee what a wonderfully informative post. Did you know I had trouble following the documentation? Maybe you should read my post more carefully and pay close attention to detail. Then you might recognise that simply copy pasting a section from the docs does not help in the least. Obviously I'm using AZ_OK wrongly. Instead of throwing attitude around about how I should just read the manual, you should actually try to make a contructive and helpful comment. If you don't have anything contructive to post, don't post at all.


Oct 8, 2002, 3:17 AM

Post #5 of 8 (2525 views)
Re: [Mordred] Archive::Zip Usage [In reply to] Can't Post

Don't worry about it, thebitch has a hardon for himself.

One thing I notice is the way you are assigning your paths.

$url = "$FORM{'fileurl'}/$filename";  
$filepath = "$FORM{'filepath'}/$filename";

This is very insecure as the url and path both look like user input but they aren't checked for validity which is a big security risk.

Check this out:


Oct 8, 2002, 3:23 AM

Post #6 of 8 (2524 views)
Re: [Mordred] Archive::Zip Usage [In reply to] Can't Post

Just thought I'd add that the message above is to thebitch. I recognise you've probably spotted the problem in AZ_OK however unlike some, I do read and research a topic before I submit myself to the probable scorn and patronising attitude that's all too prevalent on programming forums. You can consider that a post from me means I'm stumped after reading all I could get my hands on. Therefore I consider the notion that all I need to do is just read the doc again to be disrespectful and unhelpful. Maybe you don't give a shit, but respect is a two way street. You get as good as you give.

Davorg, I had checked cpan. It's where I got the module originally. I downloaded the source and read his examples and docs as well. I cobbled the above code from his examples. Thanks for the link though.


Oct 8, 2002, 3:34 AM

Post #7 of 8 (2520 views)
Re: [RedRum] Archive::Zip Usage [In reply to] Can't Post

Hi Redrum, yeah they're not being checked atm. The form variables are being passed from the admin panel of a script I'm just beginning. I'm a bit slack sometimes when I first write things and also not being so strict on input lets me play around. The script is just for me, and protected by a htaccess password and a stored blowfish encrypted password as well which I guess encourages my slackness. I'll add checking before the script goes into mainstream use :)


Oct 8, 2002, 3:38 AM

Post #8 of 8 (2520 views)
Re: [Mordred] Archive::Zip Usage [In reply to] Can't Post

so I didn't help at all? ( did you figure it out)

die "whoops!" if $zip->read( '' ) != AZ_OK;

AZ_OK is a subroutine.
"AZ_OK" is a string.
eq is the equality operator for strings.
== is the equiality operator for numbers
you need to use

if ($status == AZ_OK ) {  ...

I don't particularly care for people cussing at me, talk about respect.
I am not being disrespectful.
When I start calling you a names and cussing at you, that is when I am being disrespectfull.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives