You could also try a much simpler method, involving
PerlIO::gzip:
#!/usr/bin/perl
use strict;
use warnings;
use PerlIO::gzip;
my $Usage = "Usage: $0 filename-to-compress\n";
die $Usage unless ( @ARGV == 1 and -f $ARGV[0] );
open( IN, "<", $ARGV[0] ) or die "$ARGV[0]: $!\n";
open( GZIP, ">:gzip", "$ARGV[0].gz" ) or die "$ARGV[0].gz: $!\n";
$/ = undef;
$_ = <IN>;
print GZIP;
If you want to use this on an input file that is too big to fit in memory all at once, just use the normal I/O idiom with a while loop -- the result will be the same:
# $/ = undef;
# leave $/ at it's default value...
while (<IN>) {
print GZIP;
}
UPDATE: (2010-10-18) It seems that PerlIO::gzip should be viewed as superseded by PerlIO::via:gzip. (see PerlIO::gzip or PerlIO::via::gzip).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.