This is a good example of when to use Bash, the granularity of what Perl is giving you is unnecessary and causes one to overcomplicate the task; so there's no need to introduce it when the shell gives you much more direct access to what you're doing. You can do this with a short script that simply uses mysqldump and find.

Or if you want to get really clean, pipe the dump directly into gzip -c to get your sql.gz (no temporary files to clean up). gzip also can delete any files it's zipping, leaving you with just the .gz. Or if you have more than on, tar -cz. At least create yourself a .my.cnf file chmod'd 600 so you don't have to mess with password or put the password directly in the command (this shows up fully in the process list).

If you insist on using Perl for this, then at least make it interesting and use something like Archive::Tar::Builder to manage your dumps.

It's also perfectly okay to treat Perl scripts as utilities also that are piped together using Bash, some people tend to think you have to do it all in Perl as a monolithic thing. Perl works just as well to create small focused tools that are piped together (via STDIN and STDOUT) and managed with a Bash script.

In reply to Re: unlink files by perlfan
in thread unlink files by frank1

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.