#!/bin/perl -w

use strict;
use XML::Twig;

my $field= shift;

my $twig= new XML::Twig( twig_handlers => { player => \&player } );

if( $ARGV[0]) { $twig->parsefile( $ARGV[0]); }        # parse a file
else          { $twig->parse( \*STDIN);      }        # parse the standard input

sub player
  { my( $t, $player)= @_;
    my $prev_player= $player->prev_sibling || return; # no previous player
    my $player_name= field( $player, 'name');         # get players info
    my $prev_player_name= field( $prev_player, 'name');
    my $player_ppg= field( $player, $field);
    my $prev_player_ppg= field( $prev_player, $field);
    my $diff= $prev_player_ppg - $player_ppg;         # compute the stat difference
    print "$field difference $prev_player_name - $player_name: $diff\n";
    $t->purge_up_to( $prev_player);                   # keep the current player
  }

sub field                                             # get a field for a player
  { my( $player, $field)= @_;
    return $player->first_child( $field)->text;
  }
    
