http://qs321.pair.com?node_id=643342


in reply to Working with an Array of Array Names

If you want to name arrays, your best bet is to use a hash to an array ref. With this concept you can do this:

@{$type{'cars'}} = (1,2,3,4); @{$type('trucks'}} = (4,5,6,7);

Not only is this easier to read, but it is much more flexible to expansion and for others to maintain.

By flexible, I mean you are removing the requirement to hard code array names later in your code. You can easily access the array by the type name where ever it is needed. Also, because some types may be similar, it promotes code re-use for your stored values.

The only reason I can see to do it as you are outlining is because you are prematurely optimizing your array use. Generally, you should only optimize for speed when it is determined that a certain structure or use is a detriment to the process. Yes, hashes are more expensive, but so is follow-up maintenance.