Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: 'ID' generation issue and 'ID' format in XML::Twig

by Ieronim (Friar)
on Jul 11, 2006 at 13:49 UTC ( [id://560458]=note: print w/replies, xml ) Need Help??


in reply to 'ID' generation issue and 'ID' format in XML::Twig

Keep it simple: use set_att instead of id_seed and format the id value as you want:
#!/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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://560458]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2025-07-16 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.