in reply to Re^2: Missing values in XML::Twig Output
in thread Missing values in XML::Twig Output

When I run your code, it generates two outputs: My guess is that you want all output to go to the file and none to STDOUT. Is that correct? So, what you just posted should be the contents of the output file?
use strict; use warnings; use XML::Twig; my $out_file = 'C:\web_bu.xml'; my $t = XML::Twig->new( twig_handlers => {'display-name' => \&convert}, pretty_print => 'indented' ); $t->parse(*DATA); open (my $fh_out, '>', $out_file) or die "unable to open '$out_file' f +or writing: $!"; $t->print($fh_out); # this prints to the filehandle sub convert { my ($t, $elt) = @_; my $txt = $elt->text(); if ($txt =~ /wtw_reports/i) { $elt->set_text('SOMEGUY'); } }

Replies are listed 'Best First'.
Re^4: Missing values in XML::Twig Output
by TJRandall (Sexton) on May 03, 2011 at 15:26 UTC
    That's correct - I want to write all of the contents of the original file to an XML file, replacing the value inside the first <display-name>.
      That's what my code does. Give it a try.
        Sorry - I fat-fingered the copy-paste. (I am moron - hear me roar) Perfect - exactly what I needed. Thank you!