|No such thing as a small change|
Global symbol requires explicit package nameby cunningrat (Novice)
|on Nov 28, 2012 at 14:48 UTC||Need Help??|
cunningrat has asked for the
wisdom of the Perl Monks concerning the following question:
Relevant code snippets:
When I run this code, it complains that global symbols "%rtoa" and "@alljobs" require an explicit package name. The complaints are coming from inside the printjob subroutine. The variables are declared with "my" in the inner loop inside the main program, which means that their scope is limited to that inner loop. The ONLY place runsingle is called from is inside that inner loop, and the ONLY place printjob is called from is inside runsingle, so I'd think both printjob and runsingle should see those variables as "global".
Moving the declaration inside the runsingle subroutine doesn't change the behavior.
I don't understand why it's complaining. Would some kind soul explain it to me, please?
I could get around the error by passing those arrays and hashes as parameters... but as you can see from the printjob code, the arrays are actually multidimensional, so the resulting code would be hairy and hard to maintain.
UPDATE: nevermind, got it to work by declaring the variables inside a block that contains both subroutines. It's not elegant, but it'll do.