Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: problem with Zip::MemberRead

by fireartist (Chaplain)
on Apr 15, 2005 at 07:43 UTC ( [id://448091]=note: print w/replies, xml ) Need Help??


in reply to problem with Zip::MemberRead

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.

Replies are listed 'Best First'.
Re^2: problem with Zip::MemberRead
by ssk (Initiate) on Apr 15, 2005 at 09:03 UTC

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://448091]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-19 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found