Right on (in para 2 of pme's Re^3: Subroutine to delete one file and copy one file to another) re the sub,
  ...but uhmm, not so much re:
        "... add 'my' to the variable declarations wherever (emphasis supplied) the error messages indicates."

Not a good idea: $YEAR gets an error message at lines 20 & 22 (and possibly some others; TL, DR) while $year and several others also have multiple instances.

In this case, the $YEAR in Ln 22 is supposed to contain or represent the same value as that in Ln 20, so the one at 20 (in fact the whole list of vars there) should get a my.

But adding a my to the $YEAR in Ln 22 would break the process.

It may be that some of the vars in OP's code are instances (bad practice) of using the same name in different scopes. Simply iterating thru an edit/test cycle will probably not cure any problem of that character, but it's probable, IMHO, that some variables identified MORE THAN ONCE in the error messages are intended to be global.

In that case, adding a my before the first open parenthesis on Ln 20 will make many of Perl's help messages (because that's what error messages and warnings are)"go away". Adding a my before the first instance of each var cited in an error message may help OP to find most of the problems in the code shown. But marking all of them with mys will probably break the code and confuse the Seeker even further.


Precise language is the GodFather of precise code!


In reply to Re^4: Subroutine to delete one file and copy one file to another by ww
in thread Subroutine to delete one file and copy one file to another by shroh

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.