CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Perl to tar up list of files from array

 



Iconx
Novice

May 18, 2015, 11:50 AM

Post #1 of 3 (1564 views)
Perl to tar up list of files from array Can't Post

 Iíve searched all around for this but canít get it to work. I feed an array of file paths to a subroutine that should add all of those files with properties such as mtime,uid,gid to a single tar file but I havent been able to get it to work. Iíve mainly been messing with Archive::Tar, I've made it work with the commented piece of code but that doesnt retain the properties and this new iteration doesnt create a complete tar file, just directories or corrupt archive. Hereís the relevant piece of code:


Code
sub tar_files{ 
my @files_list = @_;

my $tar = Archive::Tar->new;
my @properties = "name, size, mtime, mode, uid, gid, linkname";

# This commented section is the first thing I tried and it doesnít retain properties but does create a tar.
# $tar->add_files(@files_list);
# $tar->write('file.tar.gz', 9);

foreach my $path (@files_list){
$tar->add_data($path, 0, \@properties);
}
$tar->write('file2.tar.gz', 9);


idea's?


FishMonger
Veteran / Moderator

May 18, 2015, 3:35 PM

Post #2 of 3 (1558 views)
Re: [Iconx] Perl to tar up list of files from array [In reply to] Can't Post

I see at least 2 problems.

1) @properties does not hold what you think.

2) The parameters you're passing to add_data() method are wrong.

You need to read the module documentation.
http://search.cpan.org/~bingos/Archive-Tar-2.04/lib/Archive/Tar.pm#$tar-%3Eadd_data_%28_$filename,_$data,_[$opthashref]_%29


(This post was edited by FishMonger on May 18, 2015, 3:36 PM)


Laurent_R
Veteran / Moderator

May 19, 2015, 8:51 AM

Post #3 of 3 (1546 views)
Re: [Iconx] Perl to tar up list of files from array [In reply to] Can't Post

Right now, properties is not an array of properties, but an array containing a string of characters listing those properties. The add_data method of Archive::Tar will not be able to use that.

Try for example this:

Code
my @properties = qw/name size mtime mode uid gid linkname/;


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives