Artimus has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone!

I wonder if someone could explain me the way I can pass parameters to my SAX handler or, maybe receive smth back after $parser->parse_file($fh) worked.

Replies are listed 'Best First'.
Re: XML::SAX parameters
by choroba (Cardinal) on Oct 02, 2015 at 12:59 UTC
    I used to be one of the teachers of this course.

    Update: As usually with callbacks, the easiest way to communicate is through closures. This example uses a lexical package-scoped variable. Note that each object has a different slot in the hash, so you can use the same class for several objects (the count is "inside-out").

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      While it all was in one file with handler package - all worked.

      After I checked it and splitted it in different modules at different places of the project and mentioned handler as needed. Parsing was working, but method for the only returning results didn't work.

      Well the solution was to put line return \@results; right to the

      sub end_document{ $self = shift; return \@results;}
      method :)