in reply to Re: my least favorite perl feature
in thread my least favorite perl feature

Not hard obviously ;-) However, I do miss the ability to say succinctly whether two things are the same "object" or not - something like Common Lisp's eq, Pop-11's == or python's is.

I admit Perl's eq works for this case 99% of the time, I don't like using it for identity checks because:

It's easy to write your own obviously - this does the job:

#! /usr/bin/perl use strict; use warnings; use Scalar::Util qw(refaddr); sub same { ref($_[0]) && ref($_[1]) && refaddr($_[0]) == refaddr($_[1]) || refaddr(\$_[0]) == refaddr(\$_[1]); }; use Test::More 'no_plan'; our ($x, $y, $z) = (1,1); *z = *x; ok same($x, $x), 'x is x'; ok same(\$x, \$x), 'ref x is ref x'; ok !same($x, $y), 'x not y'; ok same($x, $z), 'x is z';

But, in my opinion, something this basic should be in the base language... but I guess that's what perl6 is for :-)

Replies are listed 'Best First'.
Re^3: my least favorite perl feature
by diotalevi (Canon) on Feb 06, 2003 at 20:00 UTC

      Overloading == is the problem with that I'm afraid :-)

        I'll admit ignorance of overloading but wouldn't only apply if you went $obj_var_a == $obj_var_b? The snippet I showed took references to both and compared the address on the references. Wouldn't that bypass any == overloading because the newly created references aren't overloaded?


        Seeking Green geeks in Minnesota