Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

creating .tar.gz file

by srini_sun (Initiate)
on Oct 31, 2007 at 11:44 UTC ( #648225=perlquestion: print w/replies, xml ) Need Help??
srini_sun has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I am creating zip file using Zip::Archive module. But my customer want +s to make .tar.gz file instead of .zip file. Please suggest me how to achieve this using a PERL script? 1.Whetehr I have to use Archive::tar?? 2.Whetehr I can use Unix comamnd tar / gzip to make .tar.gz file? Please suggest me also give me a code snippet to make .tar.gz file Thanks Sri

Replies are listed 'Best First'.
Re: creating .tar.gz file
by moritz (Cardinal) on Oct 31, 2007 at 11:57 UTC
Re: creating .tar.gz file
by syphilis (Chancellor) on Oct 31, 2007 at 12:06 UTC
    You can do what you want using Archive::Tar so long as IO::Zlib is also installed. The Archive::Tar documentation explains this.

    You could also use 'tar' and 'gzip' commands from the command line - or from within system() commands within perl.

      The second solution looks promising, some time back I was to do the same, here it goes
      $cmd="tar -cvf xyz.tar xyz.txt 2>&1"; system($cmd);
      This creates a archive named xyz.tar containing xyz.txt then
      $cmd="gzip xyz.tar 2>&1"; system($cmd);
      will create the xyz.tar.gz file for you!!

      The world is so big for any individual to conquer

        If your tar supports it, the you can make tar directly invoke gzip in one command, creating a .tar.gz file in one go, using the -z command line switch.
        ... or even (from memory, which at my time of life ain't what it used to be) ...

        `tar -cv xyz.txt | gzip -c > xyz.tgz`;
        At last, a user level that best describes my experience :-))

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://648225]
Approved by Corion
Discipulus what?! penitentiagite monaci!

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2018-06-21 20:26 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (119 votes). Check out past polls.