Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Working with an Array of Array Names

by snopal (Pilgrim)
on Oct 07, 2007 at 23:28 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://643342]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 23:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found