[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Novice question regards subroutines



PwrSurge wrote:

>>>  if ($MainMenu = "1") {
>>>    &CheckMenu;
>>>  }
>>
>>etc., etc.
>
and Steve Swantz coached:

>>The equal sign "=" is an assignment operator, not a comparison operator.
>>When it gets to the first "if," $MainMenu is set to "1" successfully, so the
>>expression returns true. You need to use "==" for numeric comparisons and
>>"eq" for string comparisons. So what you want is:
>>
>>  if ($MainMenu == 1) {
>>    &CheckMenu;
>>  }
>>
>>or you could use:
>>
>>  if ($MainMenu eq "1") {
>>    &CheckMenu;
>>  }

To which PwrSurge replied:

>I tried using == and the perl script aborted compilation due to errors...

>I have always had the train of thought that if you're comparing letters
>(ABC) to (ABC) letters, you need to use the eq; if you're comparing numbers
>(123) to numbers (123) you always use = or ==.  Can somebody clarify that?
>I gathered that from the learning perl and programming perl books.

Please check your code again, following the examples from Steve. Use ==
with numbers, _not quoted_, or eq with strings, quoted. If you use "1", the
1 is not being compared as a number, but rather a string.

Also, never use = for comparisons; it is used to assign values to
variables/expressions.

The final thing is carefully check the rest of your code, too, following
the error messages for hints.

- Bruce

"Pessimism of the Mind; Optimism of the Will"  -- Gramsci



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch