Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: lost in my data structure.by ivancho (Hermit) |
on Nov 15, 2005 at 04:14 UTC ( [id://508477]=note: print w/replies, xml ) | Need Help?? |
The more pressing question is whether you need such a deep structure.. Whenever I see something like I generally think there's something wrong with the data structure.. As you already found out, iterating over the leaves is a nightmare - also, you'd better be very sure that the categories you divided things into (with some generic hash keys) are the only ways you'd be looking for them. Otherwise, any other search turns into an ugly (hardcoded) mixture of qw/grep map keys values/ Instead, you could consider adding some redundancy in exchange for some clarity/flexibiltiy.. For example, you could have an AoH, say, something like So, this will force you to repeat "ip1" and "ip2" and "tcp" a few times more than you need to - but you will have several degrees of freedom more than the original structure above, you will be able to iterate through all of your ports immediately, to search on any criteria and in general you will have a better idea of how a port is represented inside your structure - ie, it's just the next element of the array, rather than a leaf in some branching tree.. you can then find, say, all open ports: It's a sort of OO approach, and I think it adds a lot of flexibility here.. Update expand on why a 5-layer hash is not the best thing since sliced bread...
In Section
Seekers of Perl Wisdom
|
|