Hello, I'm new to perl and trying to unzip files with Archive::Zip qw( :ERROR_CODES :CONSTANTS )

It's working great but when I try to print the zip members they appear twice.

In fact they are already counted twice with my @members = $zip->members() and it's the same with $zip->memberNames

Any idea why? And how can I print the zip members only once or counting them correctly?

#Subroutine to Unzip Files (XXX.zip => ./XXX/) sub unzip_files_to_dir{ $logger->info("======================= START UNZIP ================= +======"); foreach (@list_FTP) { $logger->info("Trying to Unzip : $_"); #initialising zip file my $zip = Archive::Zip->new($_); if ($zip->read($_) == AZ_OK){ my $new_folder = basename($_, ".zip"); $logger->info("Creating new_folder : $new_folder"); mkpath($new_folder); #my @names = $zip->memberNames; $logger->info("Zip content :"); #print "\t".$_, "\n" for @names; # Loop through the members, printing their name, # compressed size, and uncompressed size. my @members = $zip->members(); my $nbr_members = @members; print "Number of files in zip : $nbr_members "; # print 4 when t +here are only 2 files?? foreach (@members){ print " - " . $_->fileName() . ": " . $_->compressedSize() . " (" . $_->uncompressedSize() . ")\n"; } $zip->extractTree("",$dirIN.$new_folder); } } }

I worked around that by dividing the nbr of members by 2 and breaking the foreach loop when they are printed once. But that's really ugly and sad :'(


In reply to Archive::Zip::Members print twice by Coroner

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.