Some people who continually get bitten by the = vs == thing in C and Perl
adopt the style of writing the literal first (if the test value is a
literal)...

...
    until (10 == $j)

That becomes a compile time error if you forgetfully write = instead of ==.

This doesn't work in Perl if you eliminate the literals scattered through
your code by giving them meaningful names, probably at the top of the file.
(It can work in C or C++ if one uses "the right way" of eliminating the
scattered literals.)

And it doesn't work in Perl to help with the other popular testing problem
(which doesn't arise in C):

$a = 'test';
if ($a == 'spam') {
    print "Oops...both 'test' and 'spam' are numeric 0\n"
} else {
    print "You won't see this until you test with eq\n"
}

If you haven't yet done the above, you will sooner or later.  Even if you
have done it, you'll do it again.  Using the -w flag (as one always should
except when one shouldn't) helps make that error easier to find, since Perl
is now helpful about it:

# Argument "test" isn't numeric in eq.
File 'Untitled'; Line 3
Oops...both 'test' and 'spam' are numeric 0

The -w flag helps with the = vs == thing, as well:

#!perl -w
$a = 10;

if ($a = 10) {
  print "true\n";
}

# Found = in conditional, should be ==.
File 'Untitled'; Line 4
true

  --John (who SAYS always use -w, but forgets in snippets)



At 15:33 -0800 3/9/01, Christopher Palmer wrote:
>DOOOOOOOHHHHHHH!!
>
>I HATE when I do that...that's the last time for that mistake (he
>keeps repeating to himself)
>
>Thanks,
>ctp
>
>At 3:24 PM -0800 3/9/01, ehughes wrote:
>>on 3/9/01 3:18 PM, Christopher Palmer at [EMAIL PROTECTED] wrote:
>>
>>>>  until ($j = 10) {
>>
>>until ($j == 10) {
>>
>>HTH
>>
>>Elton
>>
>>=========================================================================
>>NOVA                                          505 W. Olive Ave. Suite 550
>>Elton Hughes (Information Technology)                  Sunnyvale CA 94086
>>Phone: 408-730-7235                                     Fax: 408-730-7643
>>-------------------------------------------------------------------------

-- 
John Baxter   [EMAIL PROTECTED]      Port Ludlow, WA, USA

Reply via email to