use strict may be inconvenient in the beginning, but you will save a lot of time chasing after silly mistakes. If you get error messages because of that, read the error messages, try to understand them (IMHO the biggest mistake beginners do is to look at error and warning messages as problems instead of as helpful information). If you still don't understand, simply google for the error message, you will get lots of explanations.

The first warning message you get says it all. You used these variables only once and perl is wondering if you need them at all. Note that you use a string constant in the line "opendir (DH,"./backup/weekly");" even though you have the same value already in $backup_weekly_subdir.

UPDATED You get an error for "if (-e glob($testfile)){" because glob returns undef in a scalar context if the file doesn't exist. But perl obviously doesn't like "-e undef". Practically you are trying to test for the file existence twice, once with the glob and then with the "-e". Instead you just could check if glob returns undef or not

Functions like open and opendir return 0 aka false when the opening of the file or dir fails. You always should test for failure:

opendir (DH,$backup_weekly_subdir) or die "Can't open dir $backup_week +ly_subdir: $!\n";

Probably there is no dir backup/weekly in your current working directory, i.e. in the directory where your shell was when you started the script. Maybe an absolute path (or a relative path relative to your homedir) is better suited to this


In reply to Re: Need help with mysql dump script by jethro
in thread Need help with mysql dump script by repcsi

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.