* Rhys Hopkins <rhysh at aerotech-eu.net> [2003-03-07 12:00]: > In my reference book (Perl & XML by Ray & McIntosh) it clearly states > that one can use object methods as handlers to avoid this global > variable scenario. However, the book and the XML::Parser manpage fail > to give specific examples as to how this is accomplished, and when I > try I encounter problems.
You can pass anonymous subroutines that contain references to your object as the handlers. For example: package My::XML::Thing; ... sub parse { my $self = shift; my $parser = XML::Parser->new(Handlers => { Start => sub { $self->parse_start_field(@_) }, Char => sub { $self->parse_char_field(@_) }, }); ... The handlers for Start and Char are closures, and contain a reference to your object (in $self). (darren) -- A good magician never reveals his secret; the unbelievable trick becomes simple and obvious once it is explained. So too with UNIX.