I assume many of you are used to doing logic programming in perl but this is new to me. I wrote up a simple optree-recursing (this won't work in practice because of NULL nodes) expression which finds a given node in a tree and returns the path required to reach it. Is there a common way to write a more plausible implementation of $ROOT->(parent|sibling)* $target that doesn't require a regex to handle all the bookkeeping of tracking successes, failures and to-do work?
sub path_to_op
{
my ( $root, $tgt ) = @_;
local $op = $root;
local @path;
'' =~
/(?:
(?(?{ my $name = $op->oldname;
local $op = $op->parent;
local @path = ( @path, "$name/" ); })(?=)|(?!))
|
(?(?{ my $name = $op->oldname;
local $op = $op->sibling;
local @path = ( @path, "...," ); })(?=)|(?!))
) *
(?(?{ $$op == $$tgt })(?=)|(?!)) /x;
@path;
}