yabba has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
(jcwren) Re: Still confused
by jcwren (Prior) on Apr 08, 2001 at 09:01 UTC

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

    • Is $sum actually 0 when you start (we're pretty sure that my $sum; would set it to 0, but I never trust that kind of thing.)

    • Have you printed the values out as you go? For each loop iteration, printing out the value of all variables involved would prove to be useful.

    • Is the algorithm correct? You're recalculating the $std value everytime through the loop. I suck at math, but is this correct? Using the code you have there, I get the exact same result.

    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
      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 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.
(jcwren) Re: Still confused
by jcwren (Prior) on Apr 08, 2001 at 08:46 UTC

    How about posting part of your dataset? We really have no idea what to expect without knowing what the input is.

    --Chris

    e-mail jcwren
      The pa5c.DAT contains the following:
      Smith:70 Jones:74 Rider:80 High:82 Billie:68 Smithsonville:76