UPDATE: This has been cross-posted, and it looks like the solution is to use print():
http://stackoverflow.com/questions/29795171/modifying-xml-file-and-saving-them-in-the-same-file-using-perl-and-xmltwig#29796073
Ignore this...
I looked at the tests on CPAN (http://cpansearch.perl.org/src/MIROD/XML-Twig-3.49/t/test_3_26.t), and they use flush():
use warnings;
use strict;
use XML::Twig;
my $twig = XML::Twig->new(
pretty_print => 'indented',
twig_handlers => {
jdk => sub {
$_->set_text('JDK 1.8.0_40')->flush();
},
},
);
$twig->parsefile_inplace( 'nightly.xml', '.bak' );
__END__
<jdk>JDK 1.8.0_40</jdk>
<jdk>JDK 1.8.0_40</jdk>
I got it to create a backup (nightly.xml.bak) properly, and the original nightly.xml file was modified, but it duplicates the line for me. I am using an older version of XML::Twig, 3.37. I didn't see any open bug reports on this topic.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.