I am just going through all XML::Twig posts and ran to this one and was just testing out the code..
use strict; use warnings; use XML::Twig; my $xml = <<XML <foo> <bar> <bay V="A" /> <baz V="B" /> </bar> </foo> XML my $t = XML::Twig->new ( twig_handlers => { '/foo/bar' => sub { my $bay = $_->first_child('bay'); my $baz = $_->first_child('baz'); print $bay->att("V"); print $baz->att("V"); } } ); $t->parse ($xml);
but it says
./xml_test1.pl syntax error at ./xml_test1.pl line 17, near "my " Global symbol "$t" requires explicit package name at ./xml_test1.pl li +ne 17. Can't use global $_ in "my" at ./xml_test1.pl line 21, near "= $_" syntax error at ./xml_test1.pl line 26, near "}" Execution of ./xml_test1.pl aborted due to compilation errors.
what am I doing wrong?

In reply to Re: XML::Twig oddity by convenientstore
in thread XML::Twig oddity by holli

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.