What does [] mean here?

$self->[UTF8] = $conf->{utf8}; 

Never seen such a code before.

What does [] mean?

+4
source share
2 answers

In this case, the $self object is implemented as a link to the blessed array, and not a much more common method of using a blissful hash link. The syntax $foo->[42] refers to a single element from an array reference. UTF8 is supposedly a constant that returns a numeric index into an array.

Sometimes you see this idiom when people are convinced (as a rule, incorrectly) that a hash search on the attributes of an object leads to significant overhead and tries to optimize their code prematurely.

+10
source

[] implies that $self is a reference to a list / array (assuming the code works). This looks a little strange, although list indices should be numeric.

+3
source

All Articles