in reply to XML Twig - Isolate Element

I was in the middle of writing a long explanation on why this is normal, when it occured to me to try your code, and apparently it works just fine in XML::Twig 3.32. Which is completely wrong (not to mention baffling!). So I think I need to investigate this one a bit.

In any case the gist of the explanation was that XML::Twig works by storing trees. In order to ensure that even when twig_roots is used, it always store the root of the document. Which flush (should!) duly print when asked to. If you just use print instead of flush, then you should get what you want (and the subsequent purge should get rid of the element anyway, so you shouldn't see any increase in memory usage).

Does that help?In any case it looks like you helped me find a regression in the code, so thanks a lot.

Replies are listed 'Best First'.
Re^2: XML Twig - Isolate Element
by zacc (Novice) on Jan 03, 2008 at 17:52 UTC
    OK, I've upgraded the module to 3.32 - and FLUSH works as I would have expect (but obv not as you intended !).

    PRINT dumps out the header line for every row, which it also did under 3.- which is why I was using FLUSH.

      Sorry, I should have been more clear: you should print $record, not $nhf, this way you print exactly what you want, as GrandFather mentioned.

        Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.

        fx: Penny dropping

        Thanks both

      Well, would you know it, it appears that this is not a bug. I added this in 3.30, with a proper test (but apparently not too much docs apart from a comment in the code): when twig_roots are used, then the root is considered flushed, so flush will not output it.

      So your original code was Ok after all, and my answer should have been an easy "I know, upgrade the module, it's fixed in the current version". ;--)