I'm just not getting where to incorporate this into my script. If this is my code:
system("rsh 10.123.1.250 \"cat c:\\logs\\cpu_use1 |grep -v idle\" > cpuuseb.out"); use List::Util qw/sum/; my $file = shift @ARGV || 'cpuuseb.out'; open my $fh, '<', $file or die $!; my @cpu; while (<$fh>) { my @data = split; push @cpu, $data[4]; } $avgcpub = sum(@cpu) / @cpu; $avgcpub = $avgcpub + 0.5; $nines = 1 - 1/1e10; $value = $avgcpub; $roundedvalue = int($value + $nines); $avgcpub = 100 - $roundedvalue; print "BACKUP_AVG_CPU: $avgcpub\n"; $nines = 0; $value = 0; $roundedvalue = 0; close($fh); How do I nopt use Util and where do I put: my $sum = 0; $sum += $_ for @cpu; print $sum / @cpu; ?? Thanks, Jase. -----Original Message----- From: Chas. Owens [mailto:[EMAIL PROTECTED] Sent: 12 December 2007 12:33 To: Jase Critchley Cc: beginners@perl.org Subject: Re: Calculating Average from a file On Dec 12, 2007 5:42 AM, <[EMAIL PROTECTED]> wrote: > All, > > Thanks for your assistance in helping me with my issues. > > The script posted by Rob on the 7th works fantastic. > > However I've discovered that we have a lot of systems out there > running a previous version of perl, so much so that I am getting > errors within the util.pm. > > "Array found where operator expected at ......" > > Is there another way to calculate the average CPU from a single column > which will work in a previous version of perl? snip The sum function is just a convieniece function (which is why it is part of List::Util and not imported by default). You can get the same effect like this my $sum = 0; $sum += $_ for @cpu; print $sum / @cpu; Disclaimer: This e-mail may contain confidential or privileged information and is intended solely for the addressee. If you have received this e-mail in error, please notify the sender immediately and delete the e-mail. The unauthorised use, disclosure, copying or alteration of this e-mail is strictly forbidden. This communication is provided for information purposes only and does not form any part of a contract or agreement. Any comments or statements made herein do not necessarily reflect those of SwitchSupport. This e-mail message and any attached files have been scanned for the presence of computer viruses prior to leaving the SwitchSupport network but SwitchSupport will not be liable for direct, special, indirect or consequential damages arising from alteration of the contents of this message by a third party or as a result of any virus being passed on. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/