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

hi folks,


my problem is, i have a zip file and i need to extract certain information from the zipped file members.

I tried using Archive::Zip::MemberRead, but it seems that this Perl module is buggy.

The error it gave while exection was

Can't call method "memberNamed" without a package or object reference +at C:/Perl /site/lib/Archive/Zip/MemberRead.pm line 83.

Is there anything fault on my part?

or

can anyone help me in solving my problem (without Archive::Zip::MemberRead)

Thanx

ssk

Replies are listed 'Best First'.
Re: problem with Zip::MemberRead
by fireartist (Chaplain) on Apr 15, 2005 at 07:43 UTC

    Can you give us a small sample of code that causes this error?

    The Archive::Zip module has a test suite, which I presume passed when it was installed: so it's not likely that the module doesn't work at all - it's more likely that you're doing something not quite right.

      hi,


      pls. find below my code for your perusal.

      Also, i am using Active perl 5.8 which includes Archive::Zip

      use Archive::Zip; use Archive::Zip::MemberRead; opendir(DIR, "$ARGV[0]") || die "Can't open the '' directory"; @dr = grep(/\.zip/, readdir(DIR)); closedir(DIR); undef $/; foreach $ZipFilName (sort @dr) { my %ZipCnt = &Zip_XmlCount($ARGV[0]."\\".$ZipFilName); #### my required output print "$ZipCnt{'xml'}\t$ZipCnt{'pdf'}\t$ZipCnt{'title'}\n"; #### } sub Zip_XmlCount { my ($zipfile, $pdfCnt, $xmlCnt, %zipcnt) = @_; my $zip = Archive::Zip->new(); die "can't read '$zipfile' file" unless $zip->read($zipfile) eq 0; for($zip->memberNames()) { $xmlCnt++ if ($_ =~ /\.xml/is); # xml count $pdfCnt++ if ($_ =~ /\.pdf/is); # pdf count ########### problematic code $fh = new Archive::Zip::MemberRead($zipfile, "./$zpname"); while (defined($line = $fh->getline())) { $line =~ /<article-title>(.+)<\/article-title>/g; # articl +e-title inside xml file $title = $1; } ########### } $xmlCnt ||=0; $pdfCnt ||=0; $zipcnt{'xml'} = $xmlCnt; $zipcnt{'pdf'} = $pdfCnt; $zipcnt{'title +'} = $title; return %zipcnt; }
      ssk

        This snippet from the docs...

        $zip = new Archive::Zip("file.zip"); $fh = new Archive::Zip::MemberRead($zip, "subdir/abc.txt");
        ...shows that the 1st argument to MemberRead() should be an Archive::Zip object.

        This means your line $fh  = new Archive::Zip::MemberRead($zipfile, "./$zpname"); should be changed to $fh  = new Archive::Zip::MemberRead($zip, "./$zpname"); Also, the code would be a lot easier to understand - and debug - if you used use strict; and used variable scoping.