Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between $MAIL::xyz == 0 and $MAIN::xyz == '0'

Status
Not open for further replies.

kris2002

IS-IT--Management
May 14, 2003
21
US
My Questions :

1. I would like to know the difference between $MAIN::xyz == 0 and $MAIN::xyz == '0'.


2. Is MAIN a key word in Perl?

3. A situation in our program, $MAIN::xyz is not set to any value any where. At some point, I see a if ($MAIN::xyz == 0) condition. I can see that while the code is executed, it does go in to this condition (the condition getting satisfied i.e). Is this statement getting evaluated as "Whether the $MAIN::xyz exists or not" OR is it being evaluated as "$MAIN::xyz has a value of 0 or not".

It is a bit confusing. Any body can throw light on this one? Thanks in advance.
 
SORRY, the subject line should read "MAIN" rather than "MAIL". Thanks.
 
1. $MAIN::xyz == 0 tests whether the variable $xyz in the package MAIN is equal to zero.
$MAIN::xyz == '0' is incorrect, since it's using the numeric comparison operator == to test whether $xyz is equal to the string '0'. The string comparison operator is eq.

2. MAIN is not a keyword in Perl. However main (lowercase) is the default package name, i.e., this is the package name when no other package name is specified.
MAIN is not the same as main.

If $MAIN::xyz doesn't exist, it would not have a value of 0. It would be undefined.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top