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 | |
by haukex (Archbishop) on Aug 15, 2019 at 06:46 UTC |