Can anyone help me change Handlers in XML::Parser?

Code excerpt is as follows:

#!/usr/bin/perl -w use strict; use XML::Parser; open (FILEA, "File.txt"); my $parser = XML::Parser->new(); $parser->setHandlers(Start => \&handle_start, Char => \&handle_char, End => \&handle_end1, Final => \&final1); $parser-parsefile('File2.txt'); my $char_array_ref; my @end_array; sub handle_start{ my $e = shift; my $start_element = shift; if ($start_element eq 'coordinates'){print "hello.\n"; $parser->setHandlers(Char => \&coord); } } sub handle_char{ my $e = shift; print "HELLO There\n."; } sub coord{ my $e = shift; print "hello again.\n"; }

Use of print commands serve as a test to see which subroutines are called on Char events.

I never see "hello again" printed to the screen.

The Expat documentation suggests that you can change a handler conditionally as I am trying to do.

But I cannot seem to get it to work.

Can anyone point me in the right direction?

I would be very much obliged.

Thanks


In reply to change setHandlers XML::Parser by etlamar

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.