Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Constant subroutine main::C redefined

by BrowserUk (Pope)
on Sep 10, 2012 at 11:47 UTC ( #992732=perlquestion: print w/ replies, xml ) Need Help??
BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to shut the title warning up?


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

Comment on Constant subroutine main::C redefined
Re: Constant subroutine main::C redefined
by Corion (Pope) on Sep 10, 2012 at 11:51 UTC

    perllexwarn "tells" me

    no warnings 'redefine';

    ... but I guess there should be a way to structure your code not to redefine an existing subroutine at all :-).

    On Windows (resp. case-insensitive file systems), getting a lot of these for no obvious reason is a sure-fire symptom of loading a module using the wrong case for its name:

    use File::Find; # ... and in a code location far away use file::find;
      no warnings 'redefine';

      Doesn't work for constant subroutines

      there should be a way to structure your code not to redefine an existing subroutine at all :-).

      In this case, no.


      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

Re: Constant subroutine main::C redefined
by tinita (Parson) on Sep 10, 2012 at 11:55 UTC
    put
    no warnings "redefine";
    before the redefinition.
    this does not work from "outside", e.g. for
    no warnings "redefine"; # won't help here require Foo; delete $INC{"Foo.pm"}; require Foo;
      no warnings "redefine";

      Doesn't work for constant subroutines. Yes. It is an unusual requirement to redefine a constant ;)


      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

        like I said, it doesn't work from outside. for constants the redefinition happens in constant.pm.
        you could delete $main::{C}
Re: Constant subroutine main::C redefined
by Khen1950fx (Canon) on Sep 10, 2012 at 12:41 UTC
    Using tinita's example:
    #!/usr/bin/perl BEGIN { $ENV{'REDEFINE'} = 0; } use autodie; use common::sense; use Env::Export qw/:nowarn REDEFINE/; sub FOO () { 23 } sub FOO () { 42 }
      has the same problem with perl < 5.16

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://992732]
Approved by marto
Front-paged by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-08-29 05:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls