Thank you very much for pointing me to the right direction!

I probably would never have tried it that way since nearly all examples I have found are like my original code.

Just one comment which might be interesting for others as well:

At first, since I had not implemented a sub "new" in MyHandler, I was wondering why your solution was working at all. Then I understood that probably the "constructor" ("new") of the base class was called instead which explains why there was no compilation error.

Nevertheless, I was still unsure what was going on behind the scenes. If really "new" from the base class would have been called, I would have expected that an instance of the base class would have been returned. But this is not the case since "start_document" (from MyHandler) has been executed instead of "start_document" from the base class (the latter would not have output anything to the console).

So, for me, there was a contradiction. I really would like to understand this, but currently, I don't have the time to dig into the details. Instead, I have done it a way I am considering safe (mainly by copying and pasting examples from the web which made sense IMHO). I just added the constructor to MyHandler like that:

... package MyHandler; use base qw(XML::SAX::Base); sub new { my $s_Class = shift(); return (bless ({ }, $s_Class)); } ...

That way, "new" for sure returns the right type (object reference), and I don't have to worry about possible side effects or unexpected behavior.

Thank you very much again,

Nocturnus


In reply to Re^2: Error: Can't use string as a hash ref by Nocturnus
in thread Error: Can't use string as a hash ref by Nocturnus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.