vihar has asked for the wisdom of the Perl Monks concerning the following question:
The problem is when these individual counts are returned, the count for the second file is always count for the first file + count for second file and so on... I am not sure why it is incrementing.#Getting all individual files and number of total files @ISFiles = glob 'dir1/file.split.*'; $ISNumFiles = scalar(@ISFiles); #getISCount() function that gets count for each file sub getISCount { my @files = @_; foreach $file (@files) { open(FILE, $file) or die "Can't open `$file': $!"; while (sysread FILE, $buffer, 4096) { $count += ($buffer =~ tr/\n//); } close FILE; } return $count; } $i = 0; $j = 1; while($i < scalar(@ISFiles)) { $ISCountForFile[$j] = &getISCount(@ISFiles[$i]); $i = $i + 1; $j = $j + 1; } $combinedCount = &getISCount(@ISFiles); print "combined count - $combinedCount\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: While loop double counting
by LanX (Saint) on Nov 23, 2013 at 04:42 UTC | |
by vihar (Acolyte) on Nov 23, 2013 at 05:01 UTC | |
by vihar (Acolyte) on Nov 23, 2013 at 04:54 UTC | |
by vihar (Acolyte) on Nov 23, 2013 at 04:59 UTC | |
|
Re: While loop double counting
by Laurent_R (Canon) on Nov 23, 2013 at 11:17 UTC |