in reply to compound statement
Your biggest problem is your indentation. If your indentation is correct, you don't need comments telling you where each loop ends. Indeed, because your indentation was a mess, you had many closing braces commented incorrectly. Have a look at the reformatted code below. I've taken out most of the comments, but left some of the incorrect ones in.
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 f +older\n"; foreach my $file (glob '*.txt') { open IN, $file; while (<IN>) { if ($_ =~ m/(Exoda.*Total:)(.*\d)/) { $clearedValue =$2; push(@totalExoda,$clearedValue); } #end while foreach (@totalExoda){ $sum+= $clearedValue; print "$sum\n"; } #end if } #end foreach } }
It should be clear to you now that your inner foreach loop is inside the while but it should follow it (you don't want to sum all the digits until you've read the entire file):
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 f +older\n"; foreach my $file (glob '*.txt') { open IN, $file; while (<IN>) { if ($_ =~ m/(Exoda.*Total:)(.*\d)/) { $clearedValue =$2; push(@totalExoda,$clearedValue); } } foreach (@totalExoda){ $sum+= $_; } print "$sum\n"; } }
update: Added another correction spoted by by jeanluca
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |