in reply to Perl code looping using XML::Twig
hi ,
i am not too familiar with Twig... but in xml parser, the "product" subroutine would be called as many times as the element in the xml file are found, but you knew that...
the way i dealt with this is to have a counter to stop iteration whenever i want to.
here is snippets of your source code that i modified...
use FileHandle;
use XML::Twig;
use Net::Telnet();
my $db = "hrdm2";
my $comm = "stop-$db.sh";
my $cachedel = "No";
my $productCnt = 0; # Added counter here
.
.
.
sub product {
my ($s, $product)= @_;
my %product;
$productCnt++; #increment counter here.
print ("Debug: product: productCnt: $productCnt\n");
if ($productCnt >= 2) {
exit; # i exited, but you could do something else.
}
else {
$product{id}= $product->field( 'ServerID');
$product{name}= $product->field( 'DBName');
$product{commandstop}= $product->field( 'CommandStop');
.
.
.
.
}