I have the following piece of Perl code, but I can't understand what its doing.
use constant ANIMAL => 'rabbit';
if ($self->{+ANIMAL}) {
# Do something here
}
What does the +
sign before the constant ANIMAL
mean?
From perldoc constant
:
You can get into trouble if you use constants in a context which automatically quotes barewords (as is true for any subroutine call). For example, you can't say
$hash{CONSTANT}
becauseCONSTANT
will be interpreted as a string. Use$hash{CONSTANT()}
or$hash{+CONSTANT}
to prevent the bareword quoting mechanism from kicking in. Similarly, since the=>
operator quotes a bareword immediately to its left, you have to sayCONSTANT() => 'value'
(or simply use a comma in place of the big arrow) instead ofCONSTANT => 'value'
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With