in reply to Accessing outside variable using XML::Twig

Whenever you've got this kind of problem (which is common in event-driven systems) the easiest solution is generally to use a closure:
$self->{twig} = new XML::Twig(twig_handlers => { tag => sub { my ($twig,$tag) = @_; + $self->tagHandler($tag) +; } });
Note that the anonymous sub closes over the $self in the outer scope. Closures are extremely useful; you owe it to yourself to read up on them.

here's an introductionary article on closures.

updated formatting

Replies are listed 'Best First'.
Re^2: Accessing outside variable using XML::Twig
by KarateCowboy (Initiate) on Jan 31, 2008 at 20:45 UTC
    Wow. I read that. It is really cool. I can get this to work now! I did not expect to be able to do that!