#!/usr/bin/perl use strict; use XML::Twig; # As each tweak tag is processed, this subroutine is called. Here we will # see if any previous tweak tag had the same name element. If so, we will # overwrite the previous tweak tag with this new tweak tag's contents, then # delete the new tweak tag. sub pruner { my $this_tweak = $_; my $tweakname = $this_tweak->att('name'); my $exp = "/tcf/tweak[\@name=\"$tweakname\"]"; my @matches = $this_tweak->get_xpath($exp); print "TWEAK: "; $this_tweak->print; print " (Found $#matches other parsed tweaks with the same name)\n"; # If the tweak's name is found elsewhere, replace the first # instance with the latest one, then delete the latest one. if ($#matches == 1) { print "\tReplacing\n\t\t"; @matches[0]->print; print "\n\twith\n\t\t"; $this_tweak->print; print "\n"; $this_tweak->replace(@matches[0]); } } my $twig = XML::Twig->new(expand_external_ents => 1, twig_handlers => { 'tweak' => \&pruner } ); $twig->parsefile("/home/igo/StormLogic/MythiC/Tweaker/test5.tcf"); print "TWIG:\n"; $twig->print; print "\n";