mallet has asked for the wisdom of the Perl Monks concerning the following question:
I recently learned about object oriented programming in Perl and I wanted to convert my scripts to objects..
I have a script which uses XML::Parser, and I also have the start tag handler, the character handler and the end tag handler as methods in the class..
The problem is that when I try to pass references to these methods inside the class, I get the error
Not a code reference as line xx where line xx is the line where the handlers are set...
This is the code from inside the method start_parse
my $parser = new XML::Parser(ErrorContext => 2,Handlers => {Start => \ +&{$self->handle_start}, End => \&$self->handle_end, Char => \&$self->handle_char});
I need to have these handlers as methods because they update state variables held inside the class, so I need to pass in the $self reference to the handler somehow..
Can someone please tell me how to fix this ? Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl objects and code references
by stephen (Priest) on Apr 23, 2001 at 07:27 UTC | |
|
Re: Perl objects and code references
by gildir (Pilgrim) on Apr 23, 2001 at 16:11 UTC | |
|
Re: Perl objects and code references
by premchai21 (Curate) on Apr 23, 2001 at 07:04 UTC | |
by stephen (Priest) on Apr 23, 2001 at 07:32 UTC |