Wednesday, May 11, 2011

Multiple Files Compress::​Zlib example in perl

#!/usr/bin/perl
use strict;
use warnings;
use Compress::Zlib;

@ARGV > 0 or die "Usage: $0 <file1> [<file2> [<file3> ... ] ]\n";

for my $file (@ARGV) {
open my $fh, '<', $file or
warn "Could not open '$file': $!\n" and next;
my $gz = gzopen("$file.gz", "w") or die "Cannot open $file.gz: $!";
while (<$fh>) {
$gz->gzwrite($_);
}
$gz->gzclose();
}

No comments: