The disadvantage to Readonly is that it isn't optimized away, if it was possible. For example:
use constant DEBUG => 0;
print STDERR "foo = $foo\n" if DEBUG;
The second statement gets optimized away. But in
use Readonly;
Readonly::Scalar $DEBUG => 0;
print STDERR "foo = $foo\n" if $DEBUG;
the last statement is not optimized away, and the test is indeed performed every time the statement is encountered.
Even worse: a Readonly variable is a tied variable, so the test will be slower than it would have been if it wasn't Readonly.
|