On Mon, Oct 22, 2001 at 09:39:50AM -0700, Glenn Linderman wrote:
> 
> Indeed, you might consider "ignoring garbage" as producing a "meaningful
> result", and in the application you envision, that could be extremely useful.
> 
> However, in other applications, the fact that there was garbage on the
> 400,000th line could be critical to determining a serious flaw in the results.

I see your point, but going from: "you have to error-check to be
sure that the average you get is valid" to "you get NaN and like it"
is a bit steep.

> > More, someone has mentioned the %x{$_}++ feature, which IMHO, MUST continue
> > to work.
> >
> > NaN is a nice feature, but I don't think that it should be an EASY
> > to invoke it.

> Indeed, NaN is a nice feature; I hope I've shown that for your example there is
> a counterexample where it would be helpful to avoid silent conversions of
> garbage to zero.

No, I disagree. You're trying to protect the user from Perl's most useful
feature: coping with strangeness. Giving "your data sucks" as an answer is 
a very Python thing to do, and in *that* language, I'd say it's the right
choice. In Perl, I'd expect that:

        perl -nle '$t+=substr($_,22,2);END{print $t}'

Will do SOMETHING meaningful. NaN is not meaningful, it's the moral
equivalent of "doh!"

> I think both sets of semantics are useful; I'd personally consider your example
> a bug, and would rather see code like
> 
> while (<>)
> { my $temp = substr($_,22,2);
>   if ( is_numeric ( $temp ))
>   { $count ++;
>     $total += $temp;
>   } else
>   { $badlines ++;
>   }
> }
> printf "Average: %.2f\n", $total/$count;
> printf "goodlines: $count  badlines: $badlines\n";

Ok, so what does this mean:

0123456789012345678901234567890

Freakazoid    r x YYY 28
Samurai Jack  rwx NNN 19
Batman Beyond rw  YYY 34
Dexter's Lab  rwx YYY 55
Cowboy Beebop  wx NNN 99
Scoobie Doo   rwx YYY 01
Dallas        rwx NNNx8x
Dr. Who       rwx YYYxx8

Clearly, to us humans, the last two lines have garbage. However, unless
you're planning on changing perl SO MUCH that trailing garbage is also
ignored in string-to-number conversion, you're going to have VERY different
handling of those two lines.

For "Dallas" you get 8, and for "Dr. Who" you get NaN!

Is more error checking good? Yes. Is screwing the user who doesn't
error check the right answer? Not in my Perl programming experience....

> Yes, it takes a few extra lines to code, but adds a significant amount of
> surety to the usefulness of the results.

But converting to NaN does *not*.

> Clearly my code could be written with or without the existance of the NaN
> feature.  The existance of and use of the feature of string garbage converting
> to NaN allows your code to be used more safely, and when the result is NaN, you
> realize the need to convert your code to my code to determine the validity of
> your results.

Great, sounds-like pragma territory. I could live with a:

        use string_to_nan;

I have a hard time living with:

        use string_to_zero;

and a NaN default.

-- 
Aaron Sherman
[EMAIL PROTECTED]             finger [EMAIL PROTECTED] for GPG info. Fingerprint:
www.ajs.com/~ajs        6DC1 F67A B9FB 2FBA D04C  619E FC35 5713 2676 CEAF
  "Write your letters in the sand for the day I'll take your hand
   In the land that our grandchildren knew." -Queen/_'39_

Reply via email to