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

Hi Monks!
I have this sub in my code which at this point It will be called twice and it will be processing 2 zip files. One zip file will have image files and the other is a XML file that will have the names of these images in its node </acc>, I am matching them, that works, but when I am trying to send the right zip file in $zip, which has to be the zip file containing the images to the "do_img" sub routine to get processed, I am sending the wrong zip, its getting the zip with the XML file and not the zip file with the images, that's where I am stuck. How could I send the right zip file, at this line: do_img($zip, $accnumb, $_ );. I just cant see it.
... foreach my $zips (@zfiles) { .... # $zips will have 2 zip files getzip( $zips ); } sub getzip { my $zip_file = shift; return unless ($zip_file); print "\n Getting this first::: $zip_file\n\n"; my $zipdir = "zips/"; my $zip = Archive::Zip->new( $zipdir . $zip_file ) || die; foreach my $member ($zip->members()) { my $member_file_name = $member->fileName(); push @members_name, $member_file_name; } my @xmlfile = $zip->membersMatching( '.*\.xml' ); foreach (@xmlfile) { my $contents = $_->contents(); open my $contents_fh, '<', \$contents or die "Can't open scalar filehandle: $!"; my $first_line = <$contents_fh>; while (<$contents_fh>) { chomp; if(/<acc>(.*?)<\/acc>/gi) { my $accnumb = $1; foreach (@members_name) { if (/^($accnumb)_/g) { do_img($zip, $accnumb, $_ ); } } } } } } # End get zip

Thanks for the help!

Replies are listed 'Best First'.
Re: Getting the right ZIP file Help!
by NetWallah (Canon) on Mar 02, 2011 at 05:28 UTC
    • Pass BOTH zip file names into 'getzip'
    • Open both zip handles
    • Identify which handle contains the Img files
    • Pass the right zip handle to 'do_img'

         Syntactic sugar causes cancer of the semicolon.        --Alan Perlis