Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've found a snippet of code here that decompresses foo.tar.gz files. Unfortunately, it doesn't decompress foo.tar.Z files. Can anyone help me? Thanks, Merrick

Replies are listed 'Best First'.
Re: decompressing tar.Z files
by AgentM (Curate) on Mar 02, 2001 at 04:30 UTC
Re: decompressing tar.Z files
by BlueLines (Hermit) on Mar 02, 2001 at 04:43 UTC
    The other monks are correct in suggesting that the best way to do this is via CPAN, but if for whatever reason you can't install a module, this is how you'd do this in a shell:
    [jon@nooky jon]$ zcat foo.tar.Z | tar xvf


    BlueLines

    Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.
Re: decompressing tar.Z files
by archon (Monk) on Mar 02, 2001 at 04:31 UTC
    I believe you can use Compress::Zlib to do this. There's a section in its perldoc about "Accessing Zip Files"
Re: decompressing tar.Z files
by Tuna (Friar) on Mar 02, 2001 at 19:47 UTC
    I incorporated BlueLine's suggestion into an existing subroutine I use to read tar.gz files.
    my $gunzip = "/usr/bin/gunzip -c"; # Location of gunzip; my $Zopen = "/bin/zcat $FILENAME | /bin/tar -xvf"; my $READ; sub FancyFopen { my ($FILENAME) = @_; # my $Fhandle= new FileHandle; if (-s $FILENAME){ $READ="/bin/cat";} elsif(-s $FILENAME.".gz"){ $READ=$GUNZIP; $FILENAME=$FILENAME.".gz";} elsif (-s $FILENAME."tar.Z"){ $READ=$Zopen; $FILENAME=$FILENAME."tar.Z";} else { print "Cannot open \"$FILENAME\*\" for gunzip input\n"; } open(Fhandle,"$READ $FILENAME |") || print "Cannot open \"$FILENAME\" for input\n"; return Fhandle; }
    HTH,

    Steve