in reply to Re^2: Python 'is' command
in thread Python 'is' command

What's the point of bringing Scalar::Util::refaddr() et al to the party when == != (and all the other numeric comparators ... seem to manage just fine

Because it's the only solution in the whole thread that still works even in the presence of operator overloading? ;-)

use warnings; use strict; package Foo { my $x; use overload '<=>'=>sub{1}, 'cmp'=>sub{1}, '0+'=>sub{++$x}; } my $x = bless {}, 'Foo'; my $y = $x; print $x==$y ? "True\n" : "False\n"; # False use Scalar::Util qw/refaddr/; sub is { return refaddr $_[0] == refaddr $_[1] } print is($x,$y) ? "True\n" : "False\n"; # True

Replies are listed 'Best First'.
Re^4: Python 'is' command
by AnomalousMonk (Archbishop) on Aug 15, 2019 at 02:43 UTC

    Hmm... Hadn't thought about that.


    Give a man a fish:  <%-{-{-{-<

      Some of my first thoughts whenever it's about breaking some expected behavior are usually: prototypes, tied variables, and operator overloading :-)