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

I am still quite novice at Perl but I need to attack this script fast.

Here is the code:

#!/usr/bin/perl $| = 1; use Archive::Zip qw( :CONSTANTS ); $sandbox = "/tmp/sandbox"; opendir(D,"$sandbox") or warn("Could not open $sandbox\n");; @FILES = grep(/([A-Z]|[a-z]|[0-9])\.EXE/,readdir(D)) or die("Could not + read from $sandbox\n");; close(D); chdir("$sandbox"); for ( @FILES ) { $file = $_ ; my $unzip = Archive::Zip->new(); print("File: $file\n"); print("Attempting to deflate $file: "); $unzip->extract("$sandbox/$file") or warn("OOPS! Could not deflate + $file - $!\n") or print("done\n"); } 0
When run, I get the following:

gvc@hopper> perl -c unzip.pl unzip.pl syntax OK gvc@hopper> perl unzip.pl File: USEOB096.EXE Attempting to deflate USEOB096.EXE: Can't locate object method "extrac +t" via package "Archive::Zip::Archive" at unzip.pl line 24. gvc@hopper>
Hmmm...This is not the error I was getting a week ago when I ran this but this is a good starter. Why can't it find this module?

I will go on from this once I have resolved this issue.
Thanks for the assistance.

Edit 2001-03-28 by tye to replace <pre> with <code>

Replies are listed 'Best First'.
Re: extracting self-extracting pkzipped files with Archive::Zip
by arturo (Vicar) on Mar 28, 2001 at 22:34 UTC

    I'm not familiar with the module in question; but the first thing I'd suspect when I got an error message like

    Can't locate object method "extract" via package 
    "Archive::Zip::Archive" at unzip.pl line 24.
    

    is that there is no such method. Looking through the Archive::Zip documents, I don't see such a method listed anywhere.

    Another possibility is that the call to new failed. Here, that's unlikely since $unzip the message tells you what package the method wasn't found in, indicating that unzip was blessed into that package.

    A big problem here is that you're churning merrily along in a bunch of places without stopping to see whether you should proceed: before trying to extract anything, you should be trying to read them to see whether they are extractable. This is pointed out in the online docs.

    Once you've got those pieces of the puzzle in place, you'll have to make sure you've got that method named correctly; from what I can tell, the module's functions are mostly designed around extracting individual files from an archive, rather than simply decompressing them.

    HTH.

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      Yup. I knew that was a problem. Anyway. This is to let everyone know that the issue has been resolved. Here is the latest code.
      Please excuse the other fodder in the script (stuff at the top) I am working on the rest of the script now.
      #!/usr/bin/perl -w use Archive::Zip qw( :CONSTANTS ); use POSIX; use File::Basename; use File::Copy; use strict; ############################################################## # # $Author: $ # $Date: $ # $Locker: $ # # When - 28 Mar 2001 # Purpose - (sensored) # ## MANY thanks to Ned Konz. He is the author and maintainer ## of the Archive::Zip module. He was integral in assisting ## me in getting this blasted thing to work the way I needed ## it to work. ## # # History: # # TODO: # ############################################################## my $sandbox = "/tmp/sandbox"; opendir(D,"$sandbox") or warn("Could not open $sandbox\n"); my @FILES = grep(/(\.EXE)/,readdir(D)) or die("Read error in $sandbox +at line " . __LINE__ . "\n");; close(D); chdir("$sandbox"); for ( @FILES ) { my $file = $_ ; my $unzip = Archive::Zip->new("$file"); warn("Read error in $file at line " . __LINE__ . "!\n") if ( ! def +ined($unzip) ) and next; foreach my $member ( $unzip->members() ) { print "**** File to be extracted: " . $member->fileName() . "\n"; warn("Hmm, there was a problem\n") if ( !defined($member->extractToFileNamed( "$sandbox/" . $memb +er->fileName() )) ); } } 0
      Many thanks to the maintainer and author of the Archive::Zip module. Ned Konz was very helpful.

      The above code successfully unzips files without directories in the archive. So this will only work on archives that are meant to be unzipped in the destination directory which the archive would currently be located in.

      The way I have the script written is it will only find files that are named *.EXE because the project that I am working with has files named *.EXE that are pkzip self-extractable archives. I am only working in a Unix environment (solaris 7) and I know for a fact where these files are coming from and what they should be. If they fail, I will contact the provisioner of these files to redistribute them to my company.

      That all being said, I again appreciate the assistance I received here today.

      - Jim

      Edit 2001-03-28 by tye to replace <pre> with <code>