in reply to sumof - attempting to sum a column from each file
$sumof needs to be outside of the while loop otherwise it will keep getting reset to zero and you should be using strict and warnings or even better in my opinion a v string (v5.14). Use local variables.. that is my $x; my @z;
hope this helps, - Rudolf
use v5.14; my @allfiles = <C:/Users/user/Desktop/DOwork/filez/nabillingscript/09_ +14_2012/nas/*>; for my $file (@allfiles) { open (FILE ,'<', $file) or die $!; my $sumof = 0; while(<FILE>){ my $lines = $_; my @kbused = split(/\s+/,$lines); push(my @kilo, $kbused[2]); for my $aline (@kilo){ $aline =~ s/\D//g; push (my @onlynums, $aline); $sumof += $_ for @onlynums; } } print "$sumof\n"; } close FILE;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: sumof - attempting to sum a column from each file
by ricky5ive (Initiate) on Sep 14, 2012 at 23:29 UTC | |
by Rudolf (Pilgrim) on Sep 15, 2012 at 01:04 UTC | |
by ricky5ive (Initiate) on Sep 18, 2012 at 01:15 UTC | |
by CountZero (Bishop) on Sep 18, 2012 at 06:31 UTC | |
by Rudolf (Pilgrim) on Sep 18, 2012 at 19:35 UTC |
In Section
Seekers of Perl Wisdom