drblove27 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use Archive::Tar; my @here = Archive::Tar->list_archive("filename.tar.gz"); foreach (@here) { print "$_\n"; } print "Took $time_taken seconds to process\n";
My problem is that the tar.gz file is is 64MB, but the contents are roughly 4GB.
I guess what I should say what I really want. Each of these tar.gz files have just a single file that I need to extract that can be very large. I don't really care about the name inside the tar.gz file, I just want to extract it. Since the file is so large, I would like to extract the file, minimizing the memory hit, so I can then read the extracted contents in, line by line to do the processing that I need to do.
I really want to avoid trying to stick the whole file in memory. Is there a smarter way to do this? Or at the very least minimize the memory hit that I am going to take?
Here is my "best" attempt at this... (this is on a Windows system for *nix tricks won't save me...)
Thanks in advance!#!/usr/bin/perl -w use strict; use Archive::Tar; my $filename = "filename.tar.gz"; my $tar = Archive::Tar->new($filename); my @filenames = $tar->list_files; $tar->extract_file($filenames[0],'temp.out'); open(DATA, "temp.out"); while (<DATA>) { ... } close(DATA);
|
|---|