Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^7: Constant subroutine main::C redefined

by toolic (Bishop)
on Sep 10, 2012 at 12:50 UTC ( [id://992750]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^8: Constant subroutine main::C redefined
by BrowserUk (Patriarch) on Sep 10, 2012 at 13:18 UTC

    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
      so what about delete $main::{C}? did you try?

        It works in main, but the target won't always be main. Still trying to get the syntax right for an arbitrary package.


        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

        /divp align=right

      You need the if $] in the first definition of FOO. That should prevent it being constant-folded.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
        That should prevent it being constant-folded.

        It would. Which is why I cannot use that solution.


        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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (9)
As of 2024-04-19 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found