in reply to Question on Archive::Tar vs Archive::TarGzip

I got tired of updating my previous reply, but I wanted to point out that the snippet shown there does not meet the spec -- the directory structure is not preserved, all files end up in the single-level directory of the tar set, and if there are name collisions, data will be lost.

Getting it right is a matter of understanding File::Find (which has a reputation of being inscrutable). In this case, the first parameter needs to be a hash ref, with at least two keys: { wanted => sub{...}, no_chdir => 1 }.

That's the only thing that needs to change in the snippet. Here it is, fixed to preserve directory structure in the tar file, and this time with bash-style quotes (which I know for sure are correct and do work in a bash shell):

perl -MFile::Find -MArchive::Tar -e '$t=Archive::Tar->new(); find( { wanted=>sub{-f && $t->add_files($_)}, no_chdir=>1 }, $ARGV[0] + ); $t->write( "$ARGV[0].tar" )' some_path
(still updating... :P this time, decided to ditch the "join(...)" for the output file name -- quoting is just so much easier with bash.)