Well, first of all you made mistake, the line 6 is where the assignment is done.

:)

Second, if you separate the assignment from localizing, then no warning is produced.

um, put that in the code?

use warnings; sub RO { warn "RO" } sub SHAM { warn "SHAM" } RO(); { local *RO = sub { warn "BO" }; RO(); } SHAM(); { local *SHAM; *SHAM = sub { warn "BO" }; SHAM(); } RO(); SHAM(); __END__ RO at - line 2. Subroutine main::RO redefined at - line 5. BO at - line 5. SHAM at - line 3. BO at - line 7. RO at - line 2. SHAM at - line 3.

So, that kinda makes sense to me, when its redefined, you get warning

When its undefined, then its defined , you get no warning

So , to see if its a bug , I look at what warnings says which is

Subroutine %s redefined (W redefine) You redefined a subroutine. To suppress this warning, say { no warnings 'redefine'; eval "sub name { ... }"; }

So my new code snippet is

$ perl -le " use warnings; sub foo { warn 1 } foo(); local *foo; sub f +oo { warn 2 } foo(); " Subroutine foo redefined at -e line 1. 2 at -e line 1. Undefined subroutine &main::foo called at -e line 1.

Hmm, at compile time its redefined, but at run time its undefined

Oh right, eval

$ perl -le " use warnings; sub foo { warn 1 } foo(); local *foo; eval +q{sub foo { warn 2 }}; foo(); " 1 at -e line 1. 2 at (eval 5) line 1.

no redefined warning is given

And third take round trip

$ perl -le " use warnings; sub foo { warn 1 } foo(); { local *foo; eva +l q{sub foo { warn 2 }}; foo(); } foo(); " 1 at -e line 1. 2 at (eval 5) line 1. 1 at -e line 1.

no redefined warning is given

So , yup, the situation makes sense from a technical point, at the time the new sub is defined, the old sub doesn't exist in the current scope -- current stash -- it doesn't exist

Could perl/warnings be made to detect this case? Sure

Would it be worth it? I doubt it -- its essentially double checking

So, I don't see it as a bug or undesireable; I don't see a compelling reason to change it

Cheers


In reply to Re^4: UPDATED, mostly solved: separation of define + assignment different from combination? by Anonymous Monk
in thread 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.