in reply to (tye)Re: eq or == with references
in thread eq or == with references
References are compared according to some magical numerical values the contain (probably some address of what they refer to, but that's not important). So two references will only ever compare equal using == if they do indeed refer to the same object. However, a reference will compare equal to its numerical value.
Try this in Tye's example...
$rv = \$var; # reference to $var $num = 0+\$var; # NUMERICAL value of $rv # ($num could conceivably occur in your # program "by chance") ref $rv or die; # ASSERT: $rv is a reference !(ref $num) or die; # ASSERT: $num is NOT a reference print $rv == $num, $/; # Prints "1": a reference equals a # number.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re2: eq or == with references
by tye (Sage) on Jul 09, 2001 at 00:03 UTC |