my $DEBUG;
BEGIN { $DEBUG = $ARGV[0]; }
use if $DEBUG, 'strict';
# <-- The compiler is here because
# Perl executes use statements
# as soon as it compiles them.
# "strict" will work until the
# end of this block (namely
# until the end of the file).
print($test); # strict error if $DEBUG
The following works:
my $DEBUG;
BEGIN {
$DEBUG = $ARGV[0];
if ($DEBUG) {
require strict;
import strict;
}
}
# <-- The compiler is here because
# Perl executes BEGIN blocks
# as soon as it compiles them.
# "strict" will work until the
# end of this block (namely
# until the end of the file).
print($test); # strict error if $DEBUG
The point, however, is that the following doesn't work:
my $DEBUG;
BEGIN {
$DEBUG = $ARGV[0];
if ($DEBUG) {
eval <<'__EOI__';
use strict;
# <-- The compiler instance used
# by eval is here because
# Perl executes use statements
# as soon as it compiles them.
# "strict" will work until the
# end of this block (namely
# until the end of the code
# passed to eval).
__EOI__
}
}
print($test); # No strict error
Actually, I thought the second one wouldn't work either, but it does for the reason I gave in the comments.
|