Hellhound4 has asked for the
wisdom of the Perl Monks concerning the following question:

I have been working on and, mostly, off on a project the last couple weeks. I am trying to read a list of file names into one array a list of directory contents into another and compare the two outputting any differences. This is my first project with Perl. I'm getting errors on scope (my masks earlier declaration of variable in same scope) and one that says (Useless use of numeric GE (>=) in void context). Any help on this (or any other errors) appreciated.

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.

I updated my code in the original post. The issue now is that it doesn't seem to be storing values in the arrays. The program is intended to output values only found in one array not in both and should output 2 files, one for each. It doesn't print anything.

Err... you shouldn't do that. It kind of kills the context for all the answers that you get. These nodes stick around. Say someone finds your question a year from now and starts looking at the replies and they don't match the code in your post? All it'll do is confuse them.

You can always post new code in a reply. Or just post another question. But before you do, how about not being so quick to give up on figuring it out yourself? You won't really learn anything by continually asking how to fix this or that and just sort of pasting the solutions in. Take a few hours to try to learn at least the basics of the language you are using.

Well, that's definitely progress, and your code looks a lot better, though I recommend re-reading and understanding the latter portion of my previous post so that you can re-work your greps.

But back to your modified problem: If your code now runs, but just doesn't output what you're expecting it to, it's time to pull out the age-old debugging tool: print. Pepper your code with print statements that output the current state of various variables, which logic paths you followed, and when you're inside of loops... that sort of thing. The actual Perl debugger could be helpful, but it's harder to learn. For a short script like yours, the shortest learning curve is to just sprinkle print statements all over the place.

The idea is to look at a line of your code and think up an assertion: "I believe that before this line @something contains X, and after this line of code, @something contains that." Now put a print statement before and after demonstrating that assertion, as well as whatever variables contribute to creating the change. Run your code. Watch your assertions do what you expect, or fail. When they fail, hopefully the print statements will give you enough of a clue regarding the failure that you can figure out why it's failing.

They're nearly identical so it is the same problem in both. I changed the structure of the grep function to see if that would fix it. It didn't. The problem specifically lies in the grep line itself. This is how I understand that block to work.

When putting a smiley right before a closing parenthesis, do you:

Use two parentheses: (Like this: :) )
Use one parenthesis: (Like this: :)
Reverse direction of the smiley: (Like this: (: )
Use angle/square brackets instead of parentheses
Use C-style commenting to set the smiley off from the closing parenthesis
Make the smiley a dunce: (:>
I disapprove of emoticons
Other