Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: using Archive::Tar

by pvaldes (Chaplain)
on Oct 04, 2011 at 13:40 UTC ( #929546=note: print w/replies, xml ) Need Help??

in reply to using Archive::Tar

use strict; use warnings; use autodie; use Archive::Tar; my @filelist = (); opendir(my $dir, '/path/to/my/dir/'); while(readdir $dir) { chomp; if (!~ /(^\.\.|\.)$/){ push @filelist, $_; } } my $pack = Archive::Tar->new; $pack->create_archive('Bundle-FinalTest.tgz', COMPRESS_GZIP, @filelist +); closedir $dir;

UPDATE: A couple of changes, but Not properly working still...

a lot of "not such file: filename" error messages, I don't know why

Alternatively, you can use the old cheap way, that is guaranteed to act as you expect:

`tar -zcvvf Bundle-FinalTest.tgz /path/to/Bundle/FinalTest/dir/`;

Replies are listed 'Best First'.
Re^2: using Archive::Tar
by Tux (Abbot) on Oct 04, 2011 at 14:45 UTC

    Combine with File::Find:

    use strict; use warnings; use autodie; use Archive::Tar; use File::Find; my @fl; find (sub { -d $_ or push @fl, $File::Find::name }, "Bundle::Finaltest +"); Archive::Tar->create_archive ("Bundle-FinalTest.tar.gz", COMPRESS_GZIP +, @fl);

    Enjoy, Have FUN! H.Merijn
      thanks H.Merijin i have used your code
      what shall i do when i want to compress a FILE to .gz only? please reply asap!!!

        For compressing a single file, why use perl? You could use gzip on the command line.

        If it needs to be in perl, look at Compress::Zlib. The manual has lots of info about gzip support.

        $dest = Compress::Zlib::memGzip ($buffer); $dest = Compress::Zlib::memGunzip ($buffer);

        Enjoy, Have FUN! H.Merijn

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://929546]
[choroba]: unit tests++
[choroba]: The only problem you can't solve by adding more tests is the problem of having too many tests.
[stevieb]: choroba Been there, done that :) Better too many than not enough though!
[stevieb]: I very often write a base set of unit tests before writing any code. It helps dictate the API, and ensures my earliest of ideas stay on track.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2017-07-21 20:05 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (335 votes). Check out past polls.