#!/usr/bin/perl
use 5.016;
use strict;
use warnings;
use XML::Twig;
{
open (my $OFILE, '>:utf8', './bits.xml') or die "Could not open [./bits.xml]:\n$!\n$^E";
my $t = XML::Twig->new(
twig_roots => {
'statement' => sub { push @_, $OFILE; &_statement; 1; },
},
twig_print_outside_roots => $OFILE,
pretty_print => 'indented',
);
$t->parse(*DATA);
close $OFILE;
}
sub _statement {
my ($_twig, $stmt_element, $OFILE) = @_;
my $acct = $stmt_element->find_nodes('primary/acct', 0)->trimmed_text();
if ( $acct eq '903264' ) {
$_twig->flush($OFILE);
} else {
$_twig->purge();
}
return;
}
__DATA__
000000
Im an apple!
000000
Im a carrot!
903264
Im a potato!
000000
Im a pear!
000000
Im a pickle!
000000
Im a banana!
000000
Im an eggplant!
Oh god how did this get here i am not good with computer!
####
903264
Im a potato!
Oh god how did this get here i am not good with computer!
>
####
903264
Im a potato!
Oh god how did this get here i am not good with computer!