in reply to Re^7: Removing XML comments with regex
in thread Removing XML comments with regex

Maybe you and Jenda should avoid benchmarking tools that you don't really master.

Your first attempt was perfectly valid as a solution when performance is not an issue. But if it becomes one, then loading the entire document in memory when XML::Twig is specifically designed to avoid this, is kinda lame don't you think?

The code below is probably not faster than what you have, but a least it should not use too much memory.

#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $t= XML::Twig->new( keep_spaces => 1, comments => 'drop', twig_handlers => { _all_ => sub { $_[0]->flush +}} ) ->parsefile( "test_comments.xml") ;

Replies are listed 'Best First'.
Re^9: Removing XML comments with regex
by runrig (Abbot) on Dec 29, 2007 at 04:25 UTC
    Thanks. I knew that there must be a way to print as you go, but, not ever needing that feature, couldn't pull it out of my hat (and I meant to mention that earlier, but oh well...and I think I have actually used flush() by accident when I was looking for purge() ). Ok, "wrong solution" was maybe too strong..."not the quickest" or "not if performance is a big concern" maybe would've been more appropriate. But I don't think not mastering something will ever keep me from attempting to benchmark it :-)