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

Monk mates, Can you possibly help me with a slight insight problem. I posted a message a few days ago asking if it was possible to convert text files to excel files. The answer was yes. Good!
Then i asked if i could unzip files downloaded from an FTP site. Again the answer was yes. Good!
Now, i was wondering if it was possible to read the files without actually having to unzip them. I have found a module called Archive::Zip::MemberRead but im not sure if this does the job.

With regards to the file and the data it has, i have no idea how big the contents may be, so when using the Archive::Zip module and its implementation

use Archive::Zip; use Archive::Zip::MemberRead; $zip = new Archive::Zip("file.zip"); $fh = new Archive::Zip::MemberRead($zip, "subdir/abc.txt"); while (defined($line = $fh->getline())) { print $fh->input_line_number . "#: $line\n"; } ## $read = $fh->read($buffer, 32*1024); ## print "Read $read bytes as :$buffer:\n"; }

how can i set the file size without actually knowing its size in advance.

Replies are listed 'Best First'.
Re: Reading a zipped file
by Joost (Canon) on Apr 04, 2005 at 13:57 UTC
    What file size do you need to set?

    If you're wondering about the buffer size parameter for read(); that has nothing to do with the length of the stream/filehandle you're reading from - it's just an intermediate buffer size.

    Generally you do something like:

    binmode $fh; my $buff; my $total; while (read($fh,$buff,$max_buffer_size)) { $total .= $buff; # usually, you do something smarter than this... } # now all data is in $total.

      Ah ok.
      I was under the impression i had to set the file size before it could be unzipped. With regards to the intermediate buffer size, does this affect anything a great deal?

      Is it also possible to read the file without unzipping it? In the end i want to be able to get rid of the file so as to save space as soon as its in Excel format. Can this be done in perl?
      Ta,

      "Does the sighted man pity the blind man for loss of sight, or does the blind man pity the sighted man for lack of perception"

        Is it also possible to read the file without unzipping it? In the end i want to be able to get rid of the file so as to save space as soon as its in Excel format. Can this be done in perl?

        Maybe you're a bit unclear talking about the file: what file do you refer to, the ZIP archive file (i.e. "file.zip" in the example) or the compressed file that's contained in the archive (i.e. "subdir/abc.txt" in the example)?

        If you're dealing with the former, I don't understand your question - you can delete the ZIP file once you'r done. Assuming the latter, AFAIK all unzipping using Archive::Zip happens in memory, and I guess it's the same for Archive::Zip::MemberRead, so you won't see anything cluttering your filesystem.

        Flavio (perl -e "print(scalar(reverse('ti.xittelop@oivalf')))")

        Don't fool yourself.