I'm getting funny results. Don't know how it can happen. I'm updating the xml. Open output file. Using new technique to pass extra args to twig handlers. Passing the filehandle to twig handler, and to twig_print_outside_roots.

It all works, except I put a debug print statement in the handler. It prints to STDOUT, but it doesn't go there, it goes into the output xml.

Here's a code snippet:

open(OUT, ">$tmpdir/$fname") or die "Can't open output $tmpdir/$fname: $!\n"; my $twig = XML::Twig->new(twig_roots => { '/object/attributes/attribute' => sub { put_new_jump(@_, \*OUT, $path) }, }, twig_print_outside_roots => \*OUT, keep_encoding => 1, ); sub put_new_jump { my ($tree, $elem, $fh, $path) = @_; my $name = $elem->att('name'); print "Name: $name\n"; <blah blah blah> $elem->print($fh); }
See that 'print_outside_roots => \*OUT' works, and $elem->print($fh) works. But why is STDOUT also being redirected into the xml? Oh, here's what part of the xml looks like:
Name: CreateTime <attribute group="Graph" kind="integer" name="CreateTime">1250716389</ +attribute> Name: RevOperator <attribute group="Graph" kind="string" name="RevOperator">jwalton</att +ribute> Name: Uid <attribute group="Graph" kind="string" name="Uid">PS4PS9S</attribute> Name: DataRevisionDate <attribute group="Graph" kind="integer" name="DataRevisionDate">125080 +1191</attribute>

In reply to XML::Twig and STDOUT?? by BenHopkins

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.