in reply to searching complex data structures
One thing to say is that if this is any sane kind of config file, i.e. way smaller than Sendmail's, then who really cares about efficiency.
Next, if you mean the config data is something like a hash of hashes, of hashes, of hashes then obviously you can find your data like $val = $cfg{section}{subsection}{param}{option} and that should be very efficient.
Now if you are wanting to search the entire HoHoHoH for certain values, the most efficient way is probably going to be to make an inverted index. For example you could make a hash that looks like $inv{"$val_$instance"}="$section_$subsection_$param_$option" where $instance is just a counter which lets you maintain records for multiple occurrences of the same string in different parts of the config file without overwriting old hash entries.
The point of the inverted index is that you trade a little time at the beginning for the ease of being able to just read off the value at the end. Probably you can even use grep with a regular expression on the keys of the inverted index. Come to think of it, you could just run a pattern match on the config file itself and the heck with all this hash stuff no? Hard to see your exact requirement.
About implementing a real search algorithm, it would probably make more sense if you are talking about a lot of data and you also know a lot about the kind of data you have and where it will be in the structure.
Some other neat links I was finding in CPAN.. Search-InvertedIndex, Tie::Hash::Regex (mentions PM!), Data::Hash::Flatten (also mentions PM, and your problem!). And last but not least, Data-DRef (thanks to princepawn's post in the Flatten thread) which looks useful in the "matching_keys" and "get_value_for_key" methods (caveat emptor, haven't used it myself). Dref stuff looks neat and flattens it all for you.
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: searching complex data structures
by GardRail (Initiate) on Dec 02, 2002 at 14:53 UTC | |
by mattr (Curate) on Dec 02, 2002 at 18:51 UTC |