in reply to $^W or require warnings and import warnings;
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:
BEGIN{ if( $] >= 5.006_000 ) { require warnings; import warnings; print "Warnings on: $hi\n"; } else { $^W = 1; } } print "Warnings off: $hi\n";
With this code, the output will be something to the effect of:
Warnings on: Use of uninitialized value in mytest.pl, line xxx.... Warnings off:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: $^W or require warnings and import warnings;
by salva (Canon) on Jun 15, 2005 at 18:18 UTC | |
by renz (Scribe) on Jun 15, 2005 at 21:31 UTC | |
|
Re^2: $^W or require warnings and import warnings;
by biosysadmin (Deacon) on Jun 15, 2005 at 18:21 UTC |