in reply to Handler communication in XML::Twig

Indeed you can pass closures to new.

Have a look at Simon Cozens' Achieving Closure, which explains the process in great detail.

Basically you can do this:

my $t= XML::Twig->new( twig_handlers => { foo => sub { my_handler( @_, + @HOGS) } }); # ... sub my_handler { my( $t, $elt, @HOGS)= @_; # I would probably pass \@HOGC though

Replies are listed 'Best First'.
Re: Re: Handler communication in XML::Twig
by diotalevi (Canon) on Feb 12, 2004 at 17:45 UTC
    Do you use it that way or are you just confirming the possible? I'm after the method good X'T users use. I don't know how heavy the twig object and whether it would be preferred to retain the existing object.

      I use it a lot that way.

      I have never benchmarked the creation of the object itself, as I the type of code I write rarely parses a lot of files.