http://qs321.pair.com?node_id=948607


in reply to use of "use X"

Wow! What a great response. Thank you all for the insights!!

Am much closer to the goal, now just stuck on the "inverse, sort of" (from the Camel Book) of "use", "no". Sorry, not meaning to be cryptic. Instead, here's some code that demonstrates what I was hoping to achieve:

use strict; my $debug; BEGIN { $debug = 3; } use if ($debug > 0), 'warnings'; use if ($debug > 1), 'diagnostics'; if ($debug > 2) { no warnings 'redefine'; } run_sub(); sub run_sub { print "Running\n";} sub run_sub { print "Ran\n";} if ($debug > 3) {print "DEBUG: blah, blah, ...\n";}

Have tried a few modifications, but none eliminated the 'redefine' warnings when ($debug > 2).

Replies are listed 'Best First'.
Re^2: use of "use X"
by chromatic (Archbishop) on Jan 18, 2012 at 21:28 UTC
    Have tried a few modifications, but none eliminated the 'redefine' warnings when ($debug > 2).

    That's because it has a lexical scope, and the scope in your code is the containing block. This ugly alternative works:

    BEGIN { warnings->unimport( 'redefine' ) if $debug > 2 }

    Improve your skills with Modern Perl: the free book.

      It's not ugly - it's Perl. Thank you. Again, great explanations folks - your advice is very much appreciated.