Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Traversing arbitrarily deep and baggy structures

by ELISHEVA (Prior)
on Feb 16, 2011 at 18:47 UTC ( [id://888550]=note: print w/replies, xml ) Need Help??


in reply to Traversing arbitrarily deep and baggy structures

I'd like to second ikegami's suggestion and recommend that you take a serious look at Xpath and XSLT. There isn't much point in writing your own pattern matcher when there is a really good one out there already. XSLT can be used to transform the document once you've found the nodes of interest. However, in order to use them, you'll need to understand your document's structure, so perhaps that is putting the cart before the horse.

I devised an addressing mechanism as : { treetop => $arrayref, immedparent => $someref, ixork => $ArrayIndexOrHashKey }

I'm not sure I understand your addressing scheme - are you pairing elements (node, immediate parent)? When I traverse arbitrarily deep structures I usually use a simple array to store the descent path, like this:

sub recurse { my ($param1, $param2, ...., $aPath) = @_; $id = getIdOfCurentNode(); .... do some stuff ... if ($bNeedToRecurse) { push @$aPath, $id; recurse($param1, $param2, .... $aPath); pop @$aPath; } elsif ($bSomeProblemFound) { print "Error Blah found at node=<@$aPath>\n"; } }

it takes ages to step my way through with the debugger to find out why my search routines don't do anything useful.

Although I feel a bit awkward about pushing my own modules, I'd also like to suggest a module that I recently released on CPAN, Exception::Lite. I wrote it because I do a lot of recursive programming and needed a better way to see the stack when there is an error in my code. I too found walking through a debugger tedious and way too time consuming.

Replies are listed 'Best First'.
Re^2: Traversing arbitrarily deep and baggy structures
by anonymized user 468275 (Curate) on Feb 16, 2011 at 21:43 UTC
    The full path to the match isnt needed - but I like your module and will give it serious thought.

    One world, one people

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://888550]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-23 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found