#!/bin/perl -w use strict; use XML::Twig; my( $main_file, $search, $value )= @ARGV; # get the info we need by loading the update file #my $t_upd= new XML::Twig(); #$t_upd->parsefile( $upd_file); #my $upd_badge_id = $t_upd->root->next_elt( 'badge_id')->text; #my $upd_chore = $t_upd->root->next_elt( 'jobs'); # Process the main file my $orig = new XML::Twig( TwigHandlers => { $search => \&search, }, PrettyPrint => 'indented', ); $orig->parsefile( $main_file ); $orig->flush; # don't forget or the last closing tags won't be printed sub search { my( $orig, $search )= @_; print "hrmmm\n"; # just replace jobs if the previous badge_id is the right one if( $search->prev_elt( 'name' )->text eq $search ) { print "hrmmm\n"; $orig->replace( $value ); } $orig->flush; # print and flush memory so only one job is in there at once }