Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

Comment on creating .tar.gz file
Download Code
Re: creating .tar.gz file
by moritz (Cardinal) on Oct 31, 2007 at 11:57 UTC
Re: creating .tar.gz file
by syphilis (Canon) 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.

    Cheers,
    Rob
      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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://648225]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (13)
As of 2014-07-23 18:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (150 votes), past polls