Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: sumof - attempting to sum a column from each file

by Rudolf (Monk)
on Sep 14, 2012 at 15:53 UTC ( #993748=note: print w/ replies, xml ) Need Help??


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;


Comment on Re: sumof - attempting to sum a column from each file
Download Code
Re^2: sumof - attempting to sum a column from each file
by ricky5ive (Initiate) on Sep 14, 2012 at 23:29 UTC
    This code you posted works perfectly. Appreciate you taking the time!

      No problem at all, you should consider learning more Perl if you have the time - it is a valuable investment. Not only a powerful tool but a fun artistic language! good luck

        I would like to learn more cause I do enjoy it, but hard to figure out where to go next? Any help there would be appreciated. I enjoy Perl, I just run into issues like these and it takes the wind out of my sails. I come back to it, but takes a few days. I've taken a beginners class and read the learning perl oriely book. I have the cookbook also, but it's difficult to figure out where to go with that. I've worked a lot with modules too. I think I need to get a more concrete understanding of the low level language so I can utilize more features and make it easier.

        Any suggestions are appreciated. If anyone knows what another stepping stone would be, I would be grateful.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993748]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2014-12-21 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls