in reply to best structure for classes?

There are two components to consider. First, hashes take more memory than arrays (assuming they store similar things). Second, it's slower to access an element in a hash.

On the other hand, it's a lot more convenient to look things up by key in a hash when you're dealing with stuff that lends itself to being named and accessed out of a particular order.

Having to iterate over an array to find an appropriate element repeatedly can kill the performance benefits.

Pseudohashes are one solution, but they're not widely used or appreciated, so it's hard to recommend them. A better approach is to use the constant pragma to alias array indexes to names, and only access them through the names. This has the additional benefit or drawback of not allowing autovivification of hash keys within the object.

Most of what I use are hashes. Speed of data member access isn't a bottleneck for most of my stuff.

(Oh, and passing around a blessed reference doesn't make any difference in this case. The underlying access mechanisms do.)

Replies are listed 'Best First'.
Re: Re: best structure for classes?
by Rhandom (Curate) on Apr 20, 2001 at 00:13 UTC
    A better approach is to use the constant pragma

    Try using Benchmark on an array using constant to access the indexes. From what I've seen it lowers to to the performance of a hash (unless we're talking 10000 keys).
    I would stay with hashes as you get all of the other benefits.