Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by frozenwithjoy (Priest)
on Sep 14, 2012 at 15:55 UTC ( [id://993749]=note: print w/replies, xml ) Need Help??


in reply to sumof - attempting to sum a column from each file

Well, there are issues with your second script that others have pointed out, but why not just put the first one (which you say works) inside a loop that loops through each file?
#!/usr/bin/env perl use strict; use warnings; use autodie; @allfiles = <C:/Users/user/Desktop/DOwork/filez/nabillingscript/09_14_ +2012/nas/*>; foreach $file (@allfiles) { open (FILE ,"<", "Myfile"); ###-reads each line from the file and splits it by multiple spaces while($lines=<FILE>) { @kbused = split(/\s+/,$lines); push(@kilo, $kbused[2]); } ####-takes the number from column2 and removes the KB from the end foreach $aline (@kilo) { $aline =~ s/\D//g; push (@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 17:27 UTC
    Thank you very much. I'm going to review each of your responses and soak it all in and then reply with more.
Re^2: sumof - attempting to sum a column from each file
by ricky5ive (Initiate) on Sep 14, 2012 at 23:17 UTC
    Using strict and warnings has a lot of issues with my variable names. Not something I usually use, but obviously I need to get into the practice of.
      You should just always use them. Even if you rarely write Perl, they will probably save you hours of your life.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-20 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found