Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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
Domain Nodelet?
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 chanting in the Monastery: (4)
As of 2022-01-28 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (73 votes). Check out past polls.

    Notices?