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

Hi Monks!
I am looking for a way( by using perl) that can unzip a zipped file. Can anybody help me?
In more detail, if I want to find all lines containing 'hello' in the file xyz. But the file was zipped and it exists in the form xyz.zip in my directory.
The way I am looking for is

open (FILE, "xyz.zip");


And find some way to transfer <FILE> into an unzipped form. Then proceed as usual to find the lines containing 'hello'.
Thank you for the help!

Replies are listed 'Best First'.
Re: Unzip using perl
by davidrw (Prior) on Mar 01, 2006 at 18:02 UTC
    search for "zip" on cpan .. e.g. Archive::Zip

    Update: added snippet:
    use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $zip = Archive::Zip->new( 'xyz.zip' ); my $s = $zip->contents('xyz');
    or if it's a big file (i.e. don't want whole thing in memory), use extractMember() to write it to disk, then read through it a line at a time ..
Re: Unzip using perl
by neilwatson (Priest) on Mar 01, 2006 at 18:03 UTC
Re: Unzip using perl
by polettix (Vicar) on Mar 02, 2006 at 12:09 UTC
    In my early days here, I happened to play a little with Archive::Zip, you can find something (hopefully) useful here. And forgive me for the programming style :)

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.