use strict; use warnings; use XML::Twig; use vars qw (%PARAMS); do 'noname1.pl'; for my $key (keys %PARAMS) { my $val = $PARAMS{$key}; # Need var because sub turns it into a closure $PARAMS{$key} = sub {upd_param (@_, $val)}; } my $twigT= new XML::Twig( twig_roots => \%PARAMS, twig_print_outside_roots => 1, ); $twigT->parse (do {local $/; }); $twigT->purge; #probably not needed sub upd_param { my ($t, $param,$new_param) = @_; my $item = defined($new_param)? $new_param:$param->text; $param->set_text($item); # change it $param->print; # print updated value $t->purge; # free the memory } __DATA__ #### 7 #### $PARAMS{'CellRefinementLevel'}=7; $PARAMS{'GridCellSizeInXDirection'}=100; $PARAMS{'GridCellSizeInYDirection'}=100; #### CellRefinementLevel=7 GridCellSizeInXDirection=100 GridCellSizeInYDirection=100 #### @ARGV = 'noname.txt'; # omit if config file passed on the command line my %PARAMS = map {chomp; split '='} grep {length} <>;