Hello dear monks/experts
need your advise/suggestions on below.
Basically what iam trying to do is
open an XML file(containing many transactions) and count them(you can say a real SWIFT or any transactions with 10 fields in it)
and also i want to sum up the Total amount field found in transaction
ok i have embedded a data block with only 3 transactions and only 3 fields in each for ease sake and rest all clear from code.
#!/usr/bin/perl print "This will calculate the total amount and To no of transactions +\n"; my $totalamt = 0; while(<DATA>){ chomp; if ($_ =~ /payment amount/i){ $cnt++; while($_=~m/\<(.+?)\>(.+?)\<\/\1\>/sig){ my $value=$2; $totalamt += $value; } print $_,"\n"; } } print "The total amount found is $totalamt \n"; print "Total Transactions are $cnt \n"; __DATA__ <a> <b> <client account cred>68789790390909090489</client acco +unt cred> <Payment UTR No>MTRIN10909890896</Payment UTR No> <payment amount>700000</payment amount> </b> <b> <client account cred>9033753053985392INR</client accou +nt cred> <Payment UTR No>938573895735154</Payment UTR No> <payment amount>1222706</payment amount> </b> <b> <client account cred>9284723472047222INR</client accou +nt cred> <Payment UTR No>RP JLLKL7687</Payment UTR No> <payment amount>1437865.95</payment amount> </b> </a>

Is there any better way to do it ?
Code tested in AIX and works fine , it displays total transactions and total amount calculated correclty.
pls suggest if ima doing it non-efficiently, or any scope of improvements..many thanks in advance

In reply to Counting XML Blocks in XML file and Calculating Total Amount by harishnuti

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.