in reply to reading compressed data
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).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: reading compressed data
by kettle (Beadle) on Dec 13, 2006 at 02:34 UTC | |
by graff (Chancellor) on Dec 13, 2006 at 03:47 UTC | |
|
Re^2: reading compressed data
by kettle (Beadle) on Dec 13, 2006 at 02:28 UTC |