Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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
[1nickt]: I had an interview couople of weeks ago, heard from a principal engineer that a friend of his who works at The Google told him that the self-teaching software that determines the dynamic pricing for their adverts...
[1nickt]: ... has become so complex that there is no one at the Goole who knows what it does.
[marto]: William Gibson was right
[moritz]: a classical problem with machine learning
[1nickt]: moritz isn;t the difference today that the machine learning algos are in charge of most stuffs?
[moritz]: depends on what you mean by "most stuff"
[1nickt]: I am sure I don't know about most of the stuff that is no longer controlled by humans. I do know that it's past the point of determining consumer pricing and into things that can kill me with blunt force!
[holli]: but is this really a problem 1nickt? Nobody knows how your human taxi drivers brain works either

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2017-11-21 13:06 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (301 votes). Check out past polls.