in reply to Re^3: XML::Twig parsing Problem
in thread XML::Twig parsing Problem

HI Mirod actually $tag_name=href $tag_att=attr $att_value=cde $tag_text="the string which i want to write in place of old one" Here I want to rewrite in the file --the text of the tag which is href + and having attribute as "attr" value is "cde" and I want to relace t +his tag text with new "tag_text". there are two href tags in the file but i want to rewrite the text of +only href tag which has attr="cde" in the file. if i m using the original names in the program then it works but when +i m taking them as arguments then it's creating problem.

Replies are listed 'Best First'.
Re^5: XML::Twig parsing Problem
by sureerat (Acolyte) on Dec 02, 2008 at 18:20 UTC
    I think the problem is from the quote you mark to each variable in sub. I have modified a little bit to your code and test print, it works, please try:
    use XML::Twig; use Data::Dumper; my $xml=$ARGV[0]; my $tag_name=$ARGV[1]; my $att_name=$ARGV[2]; my $att_value=$ARGV[3]; my $tag_text=$ARGV[4]; my $twig = XML::Twig->new(twig_roots => {$tag_name => \&select_change +},); $twig->parsefile($xml); $twig->print; $twig->flush; sub select_change { my($twig,$tag_name)=@_; if ($tag_name->att($att_name) =~ $att_value) { $tag_name->set_text($tag_text); } }