Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Working with an Array of Array Names

by snopal (Pilgrim)
on Oct 07, 2007 at 23:28 UTC ( #643342=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://643342]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2020-10-28 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (264 votes). Check out past polls.

    Notices?