http://www.perlmonks.org?node_id=1060710


in reply to Is this ancient perl or just a cargo cult?

To me, this looks like a dodgy cargo cult way of doing an ordered hash.

It is neither dogdy; nor cargo-cult; nor do they pre-date hashes. Both became available at exactly the same time with the advent of blessed references circa. 5.001.

The code is using a blessed array rather than a blessed hash as the basis of its objects. This is more compact and faster than the "normal" blessed hashes.

The constants give programmer-friendly names to the fields; whilst still allowing the field lookups to be optimally efficient.

For completeness, field lookup with a hash still requires an array lookup; but first the key (field name) has to be translated into an index number. And then, if you happen to be unlucky, there might need to be a linear search as well.

blessed arrays with named constant field indexes are a less used, but perfectly valid, highly functional and more efficient way of implementing objects in Perl.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.