The following compound statement produces the wrong output. I would like you to point me to the right direction since this is above my Perl capacity.
sub Esoda_Statistika_button { my @totalExoda = 0; my $sum = 0; my $clearedValue=0; chdir "/home/props/delice/eksoda" or die "didn't make to eksoda folde +r\n"; #for every txt file in the directory foreach my $file (glob '*.txt') { # open that file open IN, $file; # read through that file line by line while (<IN>) { #if matches a digit at the specific form if ($_ =~ m/(Exoda.*Total:)(.*\d)/) { #pick that number and store it in $2 $clearedValue =$2; #add all these matched values to @totalExoda push(@totalExoda,$clearedValue); } #end while # sum up numbers of @totalExoda and store it in $sum; foreach (@totalExoda){ $sum+= $clearedValue; print "$sum\n"; } #end if } #end foreach } #end foreach } #end sub
# the above logic is wrong because of its mistaken result, can you solve this algorithm ?

In reply to compound statement by props

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.