|laziness, impatience, and hubris|
Strictly nested sub warningsby raybies (Chaplain)
|on Oct 05, 2010 at 12:16 UTC||Need Help??|
raybies has asked for the
wisdom of the Perl Monks concerning the following question:
I wrote a script that works okay, then I decided to add the "use strict" and "use warnings" to it, and all #$%^@?! has broken loose. Took me half the day to fix everything it was complaining about, but in the process I found two bugs in my script (one of which made me wonder why my script was working in the first place... ah, wondrous perl!), so I suppose it's worth the effort.
Though honesty I wish there were a way to tell perl that the outer most variables were okay not to use the package::variable name... because sticking $main::varname in some of my more specific subs, where I know what I'm doing is really tedious.
Anyhoo... I have one warning left...
Here's a very abbreviated example of the problem:
The problem is I get a warning that says:
Variable "@SymLinks" will not stay shared at ./test.pl line 21.
I think this is telling me that were I to attempt to call FindSymLinks again, that due to the internal variable being used in the nested subroutine (named inlineFind) that it would behave as though it were (c equivalent to) a static variable, retaining its values from the last time the function was called, rather than creating a fresh new @SymLinks array.
Is this a correct understanding of the warning? And is there a way to get rid of this warning?
I read somewhere that if I were to assign the sub inlineFind to a variable and provide the reference to that sub through the variable assignment, that it would do some kind of magic and fix the issue, but I haven't been able to figure a way to create a perl variable that references the nested sub.
Any ideas from the gurus?