# This looks like a constant:
ABC;
ABC = 1; # You'll never write this
Readonly, on the other hand:
if ($ABC) {
...
$ABC = 0; # Is this readonly? Scroll up
# to find out! PITA.
}
Readonly my $RO => 123;
# This compiles, too:
my Readonly $RO => 123;
# And this:
Readonly my $RO = 123; # no fat comma
# quick, what's the value of $RO?
Readonly my $LOG_LEVEL =>
$config->get('log_level');
# ...later in the code:
if ($error_condition) {
++$LOG_LEVEL; # Oops! Your application
# just crashed at the
# worst moment.
try_to_recover_somehow();
}
use constant
use constant KB => (1 << 10);
# If you *have* to print it:
print "One kilobyte is still @{[KB]} bytes\n";
constant
is much better than Readonly
.package Super::Class;
sub new {
...
$self->_init;
}
sub _init {
}
package Sub::Class;
use base qw(Super::Class);
# Unrelated function, not meant to
# override anything:
sub _init {
do_something_else_now();
}
sub new {
...
_init($self); # function call now
}
__END__