http://qs321.pair.com?node_id=413657

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

I've done a fair amount of searching on google, perlmonks, and cpan for this but have not turned up much, except Data::DRef and Data::Walker. Data::Walker provides a file-system-ish interface command line interfce for manual examination of data structures, but does not provide methods for searching the structures. Data::DRef does not appear to have "search" methods to locate keys recursively, but I will continue look more closely at it.

I have a nested data structure (hash at the top level, then mixture of hashes and arrays at lower levels, arbitrarily deep) that is read from a config file (Config::General).

I need a way to recursively search this data structure for particular hash keys, so that I can alter the data associated with them. For example, certain entries should always have a reference to an anonymous array, so I need to recursively search for a particular key, and wherever found, wrap it's value in an anonymous array if it is not already an array.

So, for example, given:

{ a => { b => 3, } b => 123, c => { b => [ 123, 456, 789, ], }, d => [ b => 456, ], }
I need something that can find all occurrences of 'b' in this data structure, so that I can examine them and change them all to array references like this:
{ a => { b => [ 3, ] } b => [ 123, ], c => { b => [ 123, 456, 789, ], }, d => [ b => [ 456, ], ], }

Similar functionality to what I need exists in File::Find, File::Find::Rule, HTML::TreeBuilder (especially it's look_down method), but these all target either filesystem or file traversal rather than perl data structure traversal.

In the interest of avoiding reinventing a wheel that I'm sure exists somewhere, but I've been unable to find, has anyone found a CPAN module to do this sort of thing?