Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^5: Constant subroutine main::C redefined

by tinita (Parson)
on Sep 10, 2012 at 12:31 UTC ( #992744=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Constant subroutine main::C redefined
in thread Constant subroutine main::C redefined

care to show some code and inform us which perl version you are using? *sigh*
talking about constants without further explanation for me means using constant.pm. everything else is just a subroutine with an empty prototype.
talking about a subroutine with an empty prototype?

$ perl5.16.0 -wE' no warnings "redefine"; sub FOO () { 23 } sub FOO () { 42 }' $


Comment on Re^5: Constant subroutine main::C redefined
Download Code
Re^6: Constant subroutine main::C redefined
by BrowserUk (Pope) on Sep 10, 2012 at 12:38 UTC

    C:\test>perl -wE"no warnings 'redefine';sub FOO(){23};sub FOO(){42};sa +y $];" Constant subroutine FOO redefined at -e line 1. 5.014002

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

      Not sure if it helps, but diagnostics shows:
      Constant subroutine FOO redefined at -e line 1 (#1) (S) You redefined a subroutine which had previously been eligible for inlining. See perlsub/"Constant Functions" for commentary and workarounds.

      Leading to Constant Functions, which mentions a workaround.

        Tried that also :(

        C:\test>perl -wE"no warnings 'redefine';sub FOO(){23};sub FOO(){42 if +$];};say$];" Constant subroutine FOO redefined at -e line 1. 5.014002

        Dropping the prototype isn't an option either because the constant getting redefined is a very rare occurence (but one that must be catered for), and I don't want to lose the benefits of compile time optimisations for the majority of cases.

        If a constant sub is redefined to be the same value, it doesn't cause the warning:

        C:\test>perl -wE"no warnings 'redefine';sub FOO(){23};sub FOO(){23};sa +y$];" 5.014002

        which will be the majority of cases, but I cannot predict when the edge case might occur so I have to try the redefinition in all cases.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        RIP Neil Armstrong

        /div
Re^6: Constant subroutine main::C redefined (diag)
by tye (Cardinal) on Sep 10, 2012 at 14:04 UTC

    perldiag says "(S) A severe warning (enabled by default)." which is probably part of the problem. But it is still easy to get around in a couple of different ways:

    #!/usr/bin/perl -w BEGIN { $SIG{__WARN__} = sub { warn @_ if $_[0] !~ /^Constant subroutine/; } } sub FOO() { 23 } sub FOO() { 42 }

    Or

    #!/usr/bin/perl -w sub FOO() { 23 } BEGIN { no warnings 'misc'; undef &FOO if ! @ARGV } sub FOO() { 42 }

    I threw in the 'if ! @ARGV' just so one can see the warning produced or suppressed by the same code.

    - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992744]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2014-07-24 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (159 votes), past polls