bobf has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, monks, who are so wise in the ways of science.*
I have a HoHoH... that looks something like this:
$VAR1 = { '1' => { '1a' => {} }, '2' => { '2a' => { '2b' => {} } '2c' => {}, } };
I need to walk through this structure and identify one or more elements that meet certain criteria. Once I find the element(s), I need to report not just the element name(s) (e.g., 2a) but also the path(s) to that element (e.g., 2 -> 2a).
I vaguely recall reading about similar problems but I suspect they focused on only traversing the structure - my searches turned up empty. I could brute-force this, but it seems like a module might already exist to do it (perhaps something along the lines of Algorithm::Loops?).
Suggestions and/or snippets are greatly appreciated. Thanks in advance.
Update: Thanks for the responses. jdporter's example gave me a good starting point.
*With proper attribution (and apologies) to Monty Python and the Holy Grail, of course. :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Recursive traversal of a HoH... and paths
by jdporter (Paladin) on Oct 09, 2006 at 19:31 UTC | |
by bobf (Monsignor) on Oct 09, 2006 at 21:41 UTC | |
by jdporter (Paladin) on Oct 09, 2006 at 22:10 UTC | |
|
Re: Recursive traversal of a HoH... and paths
by jbert (Priest) on Oct 09, 2006 at 19:19 UTC | |
|
Re: Recursive traversal of a HoH... and paths
by madbombX (Hermit) on Oct 09, 2006 at 19:31 UTC |