in reply to XML::Twig first_child_matches question

first_child_matches ($optional_condition) Return the element if the first child of the element (if it exists) passes the $optional_condition undef otherwise
The first child is yahoo, not get_this. Instead use child_matches, or children, or descendants.
  • Comment on Re: XML::Twig first_child_matches question

Replies are listed 'Best First'.
Re^2: XML::Twig first_child_matches question
by convenientstore (Pilgrim) on Nov 10, 2008 at 07:18 UTC
    hi, yes I did see that first_child_matches were wrong choice
    however, when I use child_matches, I get undesirable results
    Can't call method "att" on an undefined value at ././././xml_t line 64 +. yes [root@xmen script]#
    I think it's looping over more than necessary??
    shouldn't it enter below if statement, ONLY when it has element 'get_this'??
    for my $para ( $root->children('para') ) { if ( $para->child_matches('get_this') ) { print $para->first_child('get_this')->att('value'); } }
    **UPDATE** I tried descendent and works for me.. thank you!!!