in reply to Archive::Zip::Members print twice

Hello Coroner, and welcome to the Monastery!

Within the loop foreach (@list_FTP), the statement:

my $zip = Archive::Zip->new($_);

creates a new Archive::Zip object and initialises it with the contents of the zip file named by $_. The object now contains one member. Then, in the conditional:

if ($zip->read($_) == AZ_OK)

the contents of that same zip file are again added to the archive object, which now contains two members!

One solution is to create an empty object and populate it only via the read method:

for (@list_FTP) { $logger->info("Trying to Unzip : $_"); #initialising zip file my $zip = Archive::Zip->new(); # <-- create empty archive if ($zip->read($_) == AZ_OK) { ...

BTW, it’s better practice to pass a variable such as @list_FTP as an argument to the subroutine.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Archive::Zip members print twice
by Coroner (Novice) on Mar 03, 2016 at 14:37 UTC

    Thanks Athanasius for the reply. Works Great! I get it now ;)

    Thanks for the best practice advice too :)