Module for manipulating complex hashes?
bowei_99
created: 2006-03-03 10:24:29
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 *
Re: Module for manipulating complex hashes?
created: 2006-03-03 11:15:04

Data::Diver maybe? If that is insufficient, you probably want Class::Struct (in core) + Class::XPath.

Makeshifts last the longest.

Re^2: Module for manipulating complex hashes?
created: 2006-03-03 15:50:42
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

perlmonks.org content © perlmonks.org and Aristotle, bowei_99

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03