|more useful options|
UPDATED, mostly solved: separation of define + assignment different from combination?by perl-diddler (Hermit)
|on Feb 11, 2014 at 18:50 UTC||Need Help??|
perl-diddler has asked for the
wisdom of the Perl Monks concerning the following question:
This is no 'deep' subject or problem (that I know of), but it sorta surprised me.
If I have
I wanted to use '*', to call it as a named sub, so I had
Have used above code in a library for years w/no complaint. Then some program detected invalid args and was printing args that caused the prob. The above line generated a warning:
I was puzzled -- I thought the local would mean that each time through the code, I'd get a new instance of each var.
I figured that somehow, for some reason, the old versions of &IO_GLOB and &NIO_GLOB must stay around after the declaration and not be deleted until the end of the statement -- thus when they were replaced, I got the spurious message (which I can't figure out why it would be a problem or why it would tell me ... but, wanting just to fix the problem, I split the define and assignment:
Which got rid of the problem.
Thing is, I've used the 1st construct many times in creating sub's local to another sub (usually so they can share state & vars). This is the first time I've seen a redefinition error (perl5.14.3). Was it a fluke, or is there some repeatable way that the above could happen (other than running my original program, which did repeat it but it's far from short).
---- UPDATE ----
It seems it can happen if the subroutine that the 'local' is in is called recursively. I wondered about that -- but didn't think the case where it happened could have triggered a recursive call. It's possible something was so messed up in the calling program that some memory that would allow or disallow recursion at that point got stomped on... at least that's my best guess.
It DOES definitely happen w/recursion though... so that explains how it could happen... just not sure why it happened where it did .. but that's another issue (as that prog is still far from working! ;-)).
Just thought I'd update this w/latest findings.... Sorry for the bother...
At least now I know to split defines & assignments where they could be called recursively -- whereas didn't really know that before...