in reply to 'ID' generation issue and 'ID' format in XML::Twig
#!/usr/bin/perl use strict; use XML::Twig; my $string = '<xml> <p>here the paragraph comes</p> <p>here the paragraph comes</p> <p>here the paragraph comes</p> <p>here the paragraph comes</p> <a>here the paragraph comes</a> <a>here the paragraph comes</a> <a>here the paragraph comes</a> <a>here the paragraph comes</a> <a>here the paragraph comes</a> <a>here the paragraph comes</a> <a>here the paragraph comes</a> <a>here the paragraph comes</a> <a>here the paragraph comes</a> <a>here the paragraph comes</a> <a>here the paragraph comes</a> <a>here the paragraph comes</a> </xml>'; my $i; my $j; my $twig = new XML::Twig( twig_handlers => { p => sub { $_->set_att(id => sprintf "fig%02d", ++$i) }, #gene +rate id a => sub { $_->set_att(id => sprintf "sec%02d", ++$j) }, #gene +rate id }, pretty_print => 'indented' #print format ); $twig->parse($string); $string = $twig->sprint; print $string;
|
|---|