On Friday 14 December 2007 03:22, [EMAIL PROTECTED] 
wrote:
>
> All,

Hello,

> 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 = ();

You declare a hash %fh.

> if (-f $file  and ! $fh{$file} ) {
>     open($fh{$file}, "<$file") || DisplayError();

You populate the hash with filename keys and IO typeglob values.

>    # coolness ensues...
> }
>
>
> my @cpu;
>
> while (<$fh>) {

You should have gotten a message from 'strict' that:

Global symbol "$fh" requires explicit package name ...

Because $fh is not a valid filehandle the while loop is not executed 
and therefore the array @cpu contains nothing.


>    my @data = split;
>    push @cpu, $data[4];
> }
>
> print sum(@cpu) / @cpu;
>
> sub sum {
>    my $sum;
>    $sum += $_ foreach @_;
>    return $sum;
> }


John
-- 
use Perl;
program
fulfillment

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


Reply via email to