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
In reply to Perl objects and code references by mallet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |