I have a program which outputs an XML file. I want to change a few parameters 'on the fly' from a config file and create a modified XML file. I also want to keep the config file as simple as possible, hence separate my subroutine implementation from the config file.
So far my code compiles but my subroutine isn't being called.
Firstly, is this a good way to do it?
Secondly, why isn't it working?
The config file I have looks like:
# -*- perl -*- $PARAMS{'Task/Params/CellRefinementLevel'}=7; $PARAMS{'Task/Params/GridCellSizeInXDirection'}=100; $PARAMS{'Task/Params/GridCellSizeInYDirection'}=100; 1; # Required for end of config file.
use XML::Twig; use vars qw (%PARAMS); do 'params.cfg'; while( my($key,$val) = each(%PARAMS) ) { substr($val,0,0) = 'sub { upd_param(@_,'; $val .=' },'; $PARAMS{$key} = $val; } my $twigT= new XML::Twig( twig_roots => { %PARAMS,}, twig_print_outside_roots => 1, ); $twigT->parsefile( $task_file); $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 }
In reply to XML::twig using a hash in twig_roots by bladestonight
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |