How to zip files from perl.?

I am using Perl 5.003_7 and windowNT. I want to zip all .dat file from a folder. How do I zip that files. help me.
arogyarajxavierAsked:
Who is Participating?
 
Kim RyanIT ConsultantCommented:
You will need to dowwnload the Zlib module and install it first: http://search.cpan.org/search?dist=Compress-Zlib

use Compress::Zlib ;

chdir("/your/folder");

while <*.dat> {
  open(IN_FH, "<$_");
  $gz = gzopen($compressed_filename, "wb"); # write binary
  while (<IN_FH>) {
    $gz->gzwrite($_);
  }
  $status = $gz->gzclose() ;
  close(IN_FH);
}

0
 
proftpdCommented:
You may also use the Archive::Zip module available from CPAN to do the same task.

Ashish
0
 
arogyarajxavierAuthor Commented:
Thanks teraplane
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.