asker
asker

Reputation: 2199

What does [] mean here?

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

Never seen such code before.

What does [] mean here?

Upvotes: 4

Views: 187

Answers (2)

friedo
friedo

Reputation: 67028

In this case, the object $self is implemented as a blessed array reference rather than the far more common method of using a blessed hash reference. The syntax $foo->[42] accesses a single element from an array reference. Presumably, UTF8 is a constant that returns a numeric index into the array.

You see this idiom sometimes when people become convinced (usually incorrectly) that hash lookups on object attributes result in significant overhead and try to prematurely optimize their code.

Upvotes: 11

cHao
cHao

Reputation: 86555

The [] implies that $self is a reference to a list/array (assuming the code works). This looks a bit odd, though, as list indexes should be numeric.

Upvotes: 3

Related Questions