in reply to Syntax error - "my" within foreach loop

If you have "my" inside the loop, it makes perl create a new lexical every time around -- and throws out the previous one.

Try turning on "use diagnostics;" to see more info about the problem.

  • Comment on Re: Syntax error - "my" within foreach loop

Replies are listed 'Best First'.
Re^2: Syntax error - "my" within foreach loop
by chromatic (Archbishop) on Apr 13, 2008 at 21:10 UTC

    Which diagnostic do you have in mind?

      I've never used diagnostics with more sophistication than simply putting a "use diagnostics;" at the top of a script that's failing with a message that I don't understand.

      Though, I probably should've tried it with the OP's code before submitting my comment here, as it doesn't seem to reveal anything pithy that's not already in the orginal error message.

      In my defense, Klammer says he's a beginner, and it seemed like a good idea to recommend "use diagnostics;" in general, in case he was unaware of it.