in reply to Sort n Create XML
You can call this as with two arguments. The first is the file to be read, the second is the file to be written. If you omit the second argument, the output is written to STDOUT.use strict; use warnings; use Template; use XML::Simple; my $data = XMLin( $ARGV[0], ForceArray => 'class' ); $data->{class} = [ sort { $a->{strength}->[0] <=> $b->{strength}->[0] } @{$data->{class}} ]; #use Data::Dumper; #print Dumper ( $data ); my $tt = Template->new(); $tt->process( \*DATA, {data => $data}, $ARGV[1] ) || die $tt->error(), "\n"; __DATA__ <?xml version="1.0" encoding="UTF-8"?> <system> <header></header> [% FOR class = data.class %] <class> <name>[% class.name.0 %]</name> <strength>[% class.strength.0 %]</strength> </class> [% END %] <footer></footer> </system>
|
---|