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

Dear Monks

I can't unzip a file. I am trying this code

my $unzipped = new IO::Uncompress::Gunzip $dirname."/".$table.".sq +l.gz" or die "IO::Uncompress::Gunzip failed: $GunzipError\n";
The directory name is a directory in the current working directory in the format "dirname" (i.e. there are no dots are forward slashes in the name) and the file is called tablename.sql.gz in that directory. I am not getting any error message except for this: Use of uninitialized value $GunzipError in concatenation (.) or string at load_tables.pl line 67. I get no error message from this
my $unzipped = new IO::Uncompress::Gunzip $dirname +."/".$table.".sql.gz" or die "$!";
I have included the module use IO::Uncompress::Gunzip;

thanks for any help

Replies are listed 'Best First'.
Re: can't unzip file
by MidLifeXis (Monsignor) on Jan 28, 2011 at 17:24 UTC

    Where is $GunzipError defined or assigned?

    More verbosely (note - I have not tried this): the example use line in IO::Uncompress::Gunzip is use IO::Uncompress::Gunzip qw(gunzip $GunzipError);. The stuff within the qw tells the module that it should define $GunzipError and export it to your current package (ok, a very simplified explanation). Unless you include that, you will need to access $GunzipError probably like this: $IO::Uncompress::Gunzip::GunzipError.

    --MidLifeXis

      I tried both of those but still no error. Nothing is unzipped though
        The code was in an eval statement which was hiding the error. If the filename is incorrect i get a generic error saying 'gunzipped failed' but if i pass in the correct file name there is no error but nothing is being unzipped