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

In my perl script i have to gzip a file and pas it on to the other program. like mail server. I need help how do i Gzip and unzip files in perl script. Help is appreciated. thanks in advance. - turum khan

Replies are listed 'Best First'.
Re: How do I Gzip a file in perl script
by myocom (Deacon) on May 30, 2001 at 00:54 UTC

    A CPAN search on 'gzip' comes up with one possible solution (the other two hits aren't really relevant). If it doesn't have to be gzip, but can be some other form of compression, you might look into Compress::Zlib (or one of the other members of the Compress namespace).

Re: How do I Gzip a file in perl script
by bikeNomad (Priest) on May 30, 2001 at 01:06 UTC
    You can use Compress::Zlib to do a simple gzip (de)compression of a stream, or if you need a compressed archive (multiple files) you can use Archive::Tar.

    If you need an archive of compressed files in the ZIP format, you can use my Archive::Zip module.

(zdog ) Re: How do I Gzip a file in perl script
by zdog (Priest) on May 30, 2001 at 02:32 UTC
    I would also look into the system() function which is a bit more secure than using backticks. Something like this should work: system ("gunzip", "$file");

    Zenon Zabinski | zdog | zdog7@hotmail.com

Re: How do I Gzip a file in perl script
by malloc (Pilgrim) on May 30, 2001 at 01:20 UTC
    Just wanted to make absolutely sure that the submitt0r of this question is aware of the wonderful world of backticks.
    `gzip -9 $filename`;
    will do this for you. -malloc

      Nanny comment:
      Just make sure to untaint your data, of course, if you're going to pass user supplied data to the shell. Otherwise you'll be giving hax0rz an in to your server . . .

      Practice safer coding:

      #!/usr/bin/perl -wT use strict;

      See CGI Security and the null byte problem for more info.