On Jun 2, 2011 3:58 PM, "Uri Guttman" <u...@stemsystems.com> wrote: > > >>>>> "JG" == Jim Green <student.northwest...@gmail.com> writes: > > JG> Is there a preferred way to append a text file to the end of gzipped > JG> file? the api of File::Slurp append_file is nice, but doesn't work > JG> with gzip file... > > wow, that is an odd request. there is no direct way i think with > append_file. maybe with edit_file and calling a gzip module to unzip, > append the text and gzip the result into $_ could do it. you could also > do soemthing like this (rough code, untested and i think the -c option > is zip/unzip to stdio - fix as needed) > > > open my $in, "gunzip -c $file|" or die ; > open my $out, "| gzip -c $file|" or die ; > write_file $out, read_file( $in ) . $append_text ) ; > > the same with edit_file could be like this (again very rough code as i > don't know the gzip module api so fix this) > > use Compress:gzip ; # or whatever the real module is > use File::Slurp qw( edit_file ) ; > > edit_file { my $text = uncompress $_ ; $_ = compress "$_$append_text" } $file ; >
That looks to be pretty much the same as: zcat file ¦ script ¦ gzip -c - (Untested) ... you'd need in place editing as a part of a gzip module. IIRC gzip allows such things (or maybe that was tar). Nice addition to the module BTW. Haven't had the need for File::Slurp (used more specialized modules such as Text::CSV_XS or Web::Scraper) but this feature is definitely good. If not just because it makes how to do in place edits a no brainer.