in reply to Replacing Lines in 100 Gig file

Ah! A use for perl's flip-flip operator:

#!/usr/bin/perl -w while (<DATA>) { next if m|</root>|..m|<root>|; print; } print "</root>\n"; __DATA__ <?xml version="1.0" encoding="UTF-8"?> <root> <some_xml></some_xml> </root> <?xml version="1.0" encoding="UTF-8"?> <root> <some_xml></some_xml> </root> <?xml version="1.0" encoding="UTF-8"?> <root> <some_xml></some_xml> </root>

-b

Replies are listed 'Best First'.
Re^2: Replacing Lines in 100 Gig file
by amw1 (Friar) on Dec 17, 2004 at 18:06 UTC
    Neat. I think I know what it's doing but I'm not sure why. Could you point me in the direction of the appropriate perldoc that explains the .. foo?

      perldoc perlop. Search for "flip-flop".

      In a nutshell, though, it evaluates to false until the first condition is satisfied, and then evaluates to true until the second condition is satisfied.

      -b