All,

I've had to change the code as due to the earlier version of perl I am
running the open line would not work.

I found a workaround on the internet

use strict;
use warnings;



my $file = shift @ARGV || 'cpuuse.out';


my %fh = ();
if (-f $file  and ! $fh{$file} ) {
    open($fh{$file}, "<$file") || DisplayError();
   # coolness ensues...
}


my @cpu;

while (<$fh>) {
   my @data = split;
   push @cpu, $data[4];
}

print sum(@cpu) / @cpu;

sub sum {
   my $sum;
   $sum += $_ foreach @_;
   return $sum;
}



.... however I am getting zero values back and it is erroring
obviously about dividing by zero.

My input file looks like this.....

Thu Dec 13 04:32:09 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:33:09 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:34:09 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:35:09 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:36:09 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:37:09 093  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:38:09 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:39:09 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:40:09 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:41:09 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:42:09 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:43:09 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:44:10 093  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:45:10 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:46:10 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:47:10 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:48:10 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:49:10 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:50:10 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:51:10 093  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:52:10 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:53:10 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:54:10 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:55:11 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:56:11 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:57:11 098  000  000  000      000    000  000  000
000   -001  000  000
Thu Dec 13 04:58:11 093  000  000  000      000    000  000  000
000   -001  000  000

This is the last part of my script I can't get working. Once this is
sorted you may never hear from me again, until the next script I
write :)

Thanks in Advance.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to