|laziness, impatience, and hubris|
Re: data structure questionby roboticus (Canon)
|on Aug 30, 2013 at 12:29 UTC||Need Help??|
First I'd suggest using composite objects. It appears that you're not yet using multidimensional arrays/hashes, and I think that's part of the problem. Going by the variable names, I think you could improve things a good deal. First, here's what I'm thinking your variables mean:
If that's the case, then it looks like you're probably using code like this:
In perl, you can ask a hash or array how many elements it has, so you don't need to store the size in a separate value. So we could convert it to something like this:
If you use a multidimensional array, though, you could simplify things. Here, we'll use a second dimension on your array where element 0 is the name, and element 1 is the value:
One nice thing about multidimensional arrays like this is that frequently you can solve the problem *without* using the row number. Instead you can just loop through the array:
Of course, if you're actually just looping through arrays to find things, you'd be better served with a hash, as you can simply access each value by name:
Finally, I don't really see the point of having suffixes like "_array", "_hash", etc., so I think I'd simplify things like:
Frequently, a few well-named global hashes are fine for simple, small programs. But when your programs grow and you need to start passing things around, it's pretty simple when you use better data structures.
.... Ack! I'm late for work. I'll try to continue a little later...
When your only tool is a hammer, all problems look like your thumb.