bowei_99 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I've been writing some code that parses text from different sources and puts the results into multiply nested hashes.  I've written some subroutines to manipulate those, but they're in different scripts, many of which I just slapped together, before I realized how stupid and stubborn I was for not putting into modules. It's been on my list to refactor those into a module, but I also figure there should be a module somewhere that does that that's probably well tested, and that I could learn from.  I looked on cpan, and the closest I could find is Hash-Filler, and that's, as the name implies, more about filling in the hash.  I figure filling in the hash for me is probably more specific to what I'm parsing, but I'm looking for a module to manipulate/search/print the results. 

For example, one thing that I have now that would be nice to generalize is to give a function a reference to a hash of keywords or other parameters, say name=Bob and food=apple, and get location of the hash elements as well as associated hash elements that meet that criteria. Data::Dumper shows the actual results, but doesn't allow this kind of search functionality, and I'd also like to be able to format the output (XML, csv, etc.).

Also, I know that having arrays is more efficient, but I need to be able to look up by the key. I know of various XML and CSV modules, but haven't found any for complex hashes. Anybody know of any such module?  

====================================================
Burvil * http://www.burvil.org *
  • Comment on Module for manipulating complex hashes?

Replies are listed 'Best First'.
Re: Module for manipulating complex hashes?
by Aristotle (Chancellor) on Mar 03, 2006 at 16:15 UTC
      Great! Yes, I think Data::Diver works for the search functionality. However, it doesn't display results (e.g. dump all of or part of the nested hash) in CSV format... I think I may need to put some of my code into a module, which uses Text::CSV.

      -- Burvil