It's wrong, though.
use is a compile time statement. As soon as the compilation phase gets to the end of the statement, the use is immediately executed. No conditionals will affect it (well, there's some stuff added recently, but we'll skip that for the moment) and it will happen. Throw a use inside a BEGIN block and all that'll happen is that the use will get used before the BEGIN block is fully parsed.
If what you want is conditional inclusion, you need to do it the longer way, with require and import, both of which are runtime statements. Something like:
BEGIN {
if (DEBUG) {
require foo;
import foo;
}
}
There's more documentation on this in the use section of perlfunc. |