There are many inappropriate uses of my in your script. The one that is causing the warning that you're seeing is in line 36, where you say, "open(my $currentDirectory, my $pathToDirecory)...". That one is inappropriate because $pathToDirectory is declared on line 35 already.

Another inappropriate use is where you say push( my ..., which occurs on lines 25 and 39. The reason that's inappropriate is that every time you try to push, you're declaring a new version of the variable, masking the previous one. Consequently, the variable you're pushing onto will never have more than one element pushed to it, for every push is pushing to a new variable.

There are so many additional problems it's hard to know where to start. Line 21 slurps a file into an array, and then lines 23-26 try to read from the already exhausted file-handle.

Line 34 declares $boxBegining within the while loop's conditional, and increments it. That's going to create some wonky and possibly undefined behavior relating to the fact that 'my' has both compiletime and runtime effects. Declare that variable outside of the loop.

Line 49 should be something more like this:

@contentsOfDirectory = grep { $seen{$_} } @contentsOfDirectory;

That would eliminate the need for the grep in line 59. The same goes for line 55 and 60.

I can't explain the >= issue. But I'll bet if you fix the while loop with a 'my' in the conditional the problem will go away. In fact, it does:

while ($boxEnd >= $boxBegining++) {

Dave


In reply to Re: Question of scope and syntax by davido
in thread Question of scope and syntax by Hellhound4

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.