in reply to Still confused

No offense, but I think a basic lesson in debugging is applicable here:

I'll give you a hint: You're dividing by $avg, but I don't see it being set anywhere. Do you?

--Chris

e-mail jcwren

Replies are listed 'Best First'.
Re: (jcwren) Re: Still confused
by sierrathedog04 (Hermit) on Apr 09, 2001 at 01:13 UTC
    Actually, the value of $sum after my $sum is undefined.

    The following program demonstrates that unless a scalar is set to a value it is initially undefined:

    use strict; my $sum; unless (defined($sum)) { print '$sum is undefined', "\n"; } else { print 'The value of $sum is ', "$sum\n"; }
    This program returns the message that $sum is undefined.
At the risk of sounded redundant...
by tedv (Pilgrim) on Apr 10, 2001 at 00:56 UTC
    At the risk of sounding redundant, wouldn't perl -w catch the use of $avg when undefined, thereby making the debugging easier? All the debug tips are great, but the best one is letting perl debug for you with use strict; and -w.

    On a stylistic note, you might want to scope your variables like this:
    my ($a, $b, $c, $d);
    Instead of this:
    my $a; my $b; my $c; my $d;
    This should help keep your code from getting diluted with relatively less important text. (The computation is more important than the declarations, so it should also take up more space on screen to help focus your mind.)

    -Ted
A reply falls below the community's threshold of quality. You may see it by logging in.