If for some reason you have constraints that get in the way of installing non-core modules, but you have "gzip" and "gunzip" on your system (and in your PATH), you can just use pipeline opens:use PerlIO::gzip; open( INPUT, "<:gzip", "old.gz" ) or die "old.gz: $!"; open( OUTPUT, ">:gzip", "new.gz" ) or die "new.gz: $!"; while (<INPUT>) { # do something with a line of text... s/[\r\n]+/\n/; # for example, normalize line terminations print OUTPUT; }
There are other methods as well, involving other modules (try looking at the search results for gzip at CPAN).open( INPUT, "gunzip < old.gz |" ) or die $!; open( OUTPUT, "| gzip > new.gz" ) or die $!; while (<INPUT>) { # same as above... }
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).
In reply to Re: reading compressed data
by graff
in thread reading compressed data
by kettle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |