This is no 'deep' subject or problem (that I know of), but it sorta surprised me.

If I have
my ($a, $b ) = (sub{}, sub{});
I would normally think that 'safe'.

I wanted to use '*', to call it as a named sub, so I had

(#1) local (*IO_glob, *NIO_glob) = (#2) (sub(){'IO'>'}, sub(){'<NIO>'});
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:
sub IO_GLOB redefined at line 2. sub NIO_GLOB redefined at line 2.

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:

(#1) local (*IO_glob, *NIO_glob); (#2) (*IO_glob, *NIO_glob) = (#3) (sub(){'IO'>'}, sub(){'<NIO>'});
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...


In reply to UPDATED, mostly solved: separation of define + assignment different from combination? by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.