#!/bin/perl -w
use strict;
# this tool outputs the content of the last tag $tag in an xml file
# for the file file.xml:
# elt 1elt 2elt 3
# last_tag elt file.xml outputs elt 2
my $USAGE= "$0 [file(s)]";
my $tag= shift || die $USAGE;
my $buffer; # store the current $tag content
my $add_to_buffer=0; # 0 -> do not add to buffer, 1-> add
open( XML_IN, "pyx @ARGV | ") or die "cannot pyx input file(s): $!";
while( )
{ if( m/\($tag$/) { $add_to_buffer= 1; $buffer= ''; } # get start tag
$buffer.= $_ if( $add_to_buffer); # fill buffer
if( m/\)$tag$/) { $add_to_buffer= 0; } # get end tag
}
close XML_IN;
open( XML_OUT, "| pyxw") or die "cannot output buffer: $!";
print XML_OUT $buffer;
close XML_OUT;
# I need this to output the last line on my linux box with Perl 5.6.1
print "\n";