Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: use of "use X"

by Anonymous Monk
on Jan 18, 2012 at 19:28 UTC ( #948607=note: print w/replies, xml ) Need Help??

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2022-08-09 22:23 GMT
Find Nodes?
    Voting Booth?

    No recent polls found