Hello all,

I am creating a small helper script to create/delete webs. I decided I wanted to have the script archive all of the files in the web directory and place the tar file in a defunct directory. After searching around on CPAN and the like, I decided to use File::Find to traverse the directory for all files, and Archive::Tar to archive/compress the files. Here is what I have now:

sub del_web() { ... my($tar) = Archive::Tar->new(); $tar->read("$web_to_del.tar.gz",1); find(\&archive, "$web_base/$web_to_del"); $tar->write("$defunct_dir/$web_to_del.tar.gz",1); sub archive { $tar->add_files($File::Find::name); } # line 394 ... }
This code works, but, I have two issues with this: I get this warning:
Variable "$tar" will not stay shared at web_admin.pl line 394.
I don't quite understand the warning (I am quite new to Perl). Also, the files are archived with the full path from root. Preferably, I would like the files to get stored from the relative path of the web directory. I haven't been able to get this to work properly. For example, the way the tar files get created now:
/long/full/path/to/webdir /long/full/path/to/webdir/www ...
The way I want them:
webdir/ webdir/www webdir/cgi-bin ...
This is just a preference, but it would be nice.

If anyone has any suggestions on a better way to do this I would glady appreciate them.

Thanks,

Bren


In reply to Better way to use File::Find and Archive::Tar by brendonc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.