in reply to Re: Zipping an array problem
in thread Zipping an array problem

One more question: with using the foreach loop, how do I create a loop so that I only zip 3000 files at a time, and never zip the same files more than once? I know that I need to use a loop, and add a number to the end of the zipped file (ex. - textFiles1.zip, textFiles2.zip, etc.) to differentiate them so the zipped files are not overwritten in the destination directory (it will ultimately be a MySQL db) each time.

I've been working today for 14 hours, and I'm getting more confused the more I think about it.

I'll next be working on unzipping the textFiles.zip and dropping them in the db.

Replies are listed 'Best First'.
Re^3: Zipping an array problem
by hipowls (Curate) on Feb 17, 2008 at 06:37 UTC

    Get some rest;) You'll work better for it.

    You need to chop @files into chunks of 3,000, or less for the end. I'll not duplicate all the code, this is just an outline.

    use List::Util qw(min); foreach my $seq ( 0 .. $#files/3_000 ) { my $zip = Archive::Zip->new(); my $start = $seq * 3_000; my $end = min ( $#files, $start + 2_999 ); foreach my $i ( $start .. $end ) { $zip->addFile( $files[$i], basename $files[$i] ); } $zip->writeToFileNamed("test-$seq.zip"); }