in reply to Putting XML::Twig to the test

The problem here is that you flush the in-memory tree exactly twice: once when you hit the record you want to update, and once at the very end, when the file is all parsed.

In your case, what you need is to use the twig_roots option, which will only process the 1 record you want to update, with the (awfully named) twig_print_outside_roots option, that will output, untouched, everything else:

my $twig= new XML::Twig( twig_roots => { 'Person[@id="50000"]' => \&Person }, twig_print_outside_roots => 1, );

You don't need the last flush, at the end of the code. And I thought that you would have to replace the call to flush in the sub body by a call to $person->print, but it looks like flush is smart enough to do what you mean, so no change needed there.

Does this help?

Replies are listed 'Best First'.
Re^2: Putting XML::Twig to the test
by dHarry (Abbot) on Aug 18, 2008 at 13:56 UTC

    Thanks for the quick response! The first tests I ran look promising. It will take some time run them on the really big files. I am gathering some stats on processing big XML files, big meaning up to 688 MB. I already tried the twig_roots and twig_print_outside_roots options but apparently I made the same flush mistake.

    Cheers
    dHarry