#!/bin/perl -w

#########################################################################
#                                                                       #
#  This example displays the information for a single player            #
#  It uses the finish method                                            #
#                                                                       #
#########################################################################

use strict;
use XML::Twig;

my $name= shift;
my $stat= shift;

my $twig= new XML::Twig( twig_handlers => 
            { player => sub { player(@_, $name, $stat); } } # pass the additionnal args
                       );                                   # just to be extra clean

$twig->parsefile( "nba.xml");    # process the twig
exit;

sub player
  { my( $twig, $player, $name, $stat)= @_;
    my $player_name= $player->first_child( 'name')->text;
    if( $player_name=~ /$name/i)
      { my $stat_value= $player->first_child( $stat)->text;
        print "$player_name: $stat_value $stat\n"; 
        $twig->finish;
      }
    else
      { $twig->purge; }                                      # keep a low profile
  }
