http://www.perlmonks.org?node_id=948455


in reply to use of "use X"

By the way, you need to hide the 'use module' within an eval, to control whether it happens or not, or else use the module 'if' ( use if CONDITION, MODULE => ARGS ).

As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Replies are listed 'Best First'.
Re^2: use of "use X"
by ikegami (Patriarch) on Jan 18, 2012 at 06:32 UTC

    Using eval would delay the directive to runtime, but it needs to be active at runtime to affect code.

    >perl -e"eval 'use warnings; 1' or die $@; print undef;" >perl -e"use warnings; print undef;" Use of uninitialized value in print at -e line 1.

    And you can't wrap it in a BEGIN because that would introduce a lexical scope.