"be consistent" | |
PerlMonks |
Re: $^W or require warnings and import warnings;by davido (Cardinal) |
on Jun 15, 2005 at 17:55 UTC ( [id://466992]=note: print w/replies, xml ) | Need Help?? |
The code is actually sort of a failed attempt. The author seems to realize that the use directive occurs at compiletime, and is not easily conditionalized. So he uses the runtime-executed 'require' method of invoking a module conditionally. However, he does it within a lexical block ( if(....){ lexical block } ). The warnings pragma is lexically scoped to the block in which it is invoked, so he is only turning warnings on for a brief instant, which will not have any effect outside the if conditional block. Even if it did extend past the if(){...} block, it would be limited by the lexical scope of the BEGIN{...} block. You can observe this fact by modifying the code as follows:
With this code, the output will be something to the effect of:
In other words, the second use of uninitialized value is in a lexical scope not covered by warnings, and thus the use of uninitialized value is not reported the second time. Dave
In Section
Seekers of Perl Wisdom
|
|