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.)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.