Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: XML::Twig oddity

by convenientstore (Pilgrim)
on Nov 15, 2008 at 05:24 UTC ( [id://723773]=note: print w/replies, xml ) Need Help??


in reply to XML::Twig oddity

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?

Replies are listed 'Best First'.
Re^2: XML::Twig oddity
by Anonymous Monk on Nov 15, 2008 at 07:10 UTC
Re^2: XML::Twig oddity
by convenientstore (Pilgrim) on Nov 15, 2008 at 07:34 UTC
    that was silly of me
    thank you for pointing it out
    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);
      hi :) you should also click the correct "reply" link, or "comment on" link, that way you avoid talking to yourself, and readers can follow what is going on :)
        that's what happens to all programmer eventually no?
        talking to themselves was common pratice I thought
        Just kidding.. I got you.. thank you for your help!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://723773]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-23 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found