Re: Fwd: validator/httpd/cgi-bin check

On Wed, 2002-10-09 at 07:05, Martin Duerst wrote:

> Just to make sure that I understand what's going on:
> 
> my original version was:
>     return $encodingA && $encodingB && $encodingA ne $encodingB;

Yep, that works.

> your first version was:
>     return $encodingA && $encodingB and $encodingA ne $encodingB;

No.  That was Terje's change in
<http://dev.w3.org/cvsweb/validator/httpd/cgi-bin/check.diff?r1=1.234&r2=1.235&f=h>, which actually broke things.

> your current version is:
>     return (($encodingA && $encodingB) and ($encodingA ne $encodingB));

Yes.  That works again, and uses the "and" Terje seems to love :)

> I think that my original version was correct, yes?
> I don't understand why you want to make a difference between
> the first logical 'and' and the second logical 'and', both
> are equivalent.

No, "and" and "&&" are *not* the same in Perl.  See man perlop for
details.  But I agree that I put in too many parens there.  Just for
fun, try the script at the end of this message for a demonstration about
the logical and operator precedence.

That's why I personally never use the "and" form.  Mixing "and" and "&&"
is always IMHO either 1) wrong 2) hard to read correctly.

>     return $encodingA && $encodingB && ($encodingA ne $encodingB);
> 
> Please change it to your preferred version.

Ok, this one it is.

----------------------------------------------------------------------------
#!/usr/bin/perl

sub conflict1 {
  my $encodingA = shift;
  my $encodingB = shift;
  return $encodingA && $encodingB && $encodingA ne $encodingB;
}

sub conflict2 {
  my $encodingA = shift;
  my $encodingB = shift;
  return $encodingA && $encodingB and $encodingA ne $encodingB;
}

print conflict1('utf-8', 'utf-8') ? "yes c1" : "no c1", "\n";
print conflict2('utf-8', 'utf-8') ? "yes c2" : "no c2", "\n";

-- 
\/ille Skyttä
ville.skytta at iki.fi

Received on Wednesday, 9 October 2002 03:08:00 UTC