#!/usr/bin/perl use strict; use warnings; use XML::Rules; print "This will calculate the total amount and To no of transactions \n"; my $totalamt = 0; my $cnt = 0; my $parser = XML::Rules->new( stripspaces => 7, rules => { _default => '', b => sub {++$cnt;return}, payment_amount => sub {$totalamt+=$_[1]->{_content};return}, }); $parser->parse(\*DATA); print "The total amount found is $totalamt \n"; print "Total Transactions are $cnt \n"; __DATA__ 68789790390909090489 MTRIN10909890896 700000 9033753053985392INR 938573895735154 1222706 9284723472047222INR RP JLLKL7687 1437865.95 #### #!/usr/bin/perl use strict; use warnings; use XML::Rules; print "This will calculate the total amount and To no of transactions \n"; my $parser = XML::Rules->new( stripspaces => 7, start_rules => { a => sub { $_[4]->{pad}{count}=0; $_[4]->{pad}{total}=0; 1; } }, rules => { _default => '', b => sub {++ $_[4]->{pad}{count}; return}, payment_amount => sub {$_[4]->{pad}{total} += $_[1]->{_content};return}, a => sub {return %{$_[4]->{pad}}} }); my $data = $parser->parse(\*DATA); print "The total amount found is $data->{total}\n"; print "Total Transactions are $data->{count}\n"; __DATA__ ...