Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:
At this point, you might be asking why I am not using XML::Twig's built in handlers. As far as I can tell, you can only define them to be subroutine references and the argument list is fixed by XML::Twig. There are some particularly ugly solutions to this problem I have thought of. For instance, I could modify a global in the handler and then copy of the data structure to a lexical outside of the handler and undef the global. I could also use some currying/closure/symbol table manipulation but none of that seems very elegant.for my $child ($root->children) { my $handler = $child->tag; if ($dispatch{$handler}) { $dispatch{$handler}->($child, $data_struct); } else { die "Haven't written handler for '$handler' yet"; } }
My question is this: Is there a smarter way to do this than rolling my own dispatch table? I am locked in to use Expat so if you suggest another XML module it would need to be using the Expat library under the table.
Cheers - L~R
|
|---|