in reply to The trap of reference numification

I agree. No one should ever accidentally do math on a ref, without getting a warning (maybe even an error).

If the Perl Gods want to do this for some reason, give them a mechanism to turn it off:

no warnings refnum;
I would even go so far as to say comparison should be strings only -- what better way to reinforce the notion that math is not useful on refs (unless you're doing something naughty under the hood).

And if you're still convinced you need to do math on refs, you can grab the digits out with a regex. At least then it will be painfully obvious for the next Perler.

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^2: The trap of reference numification
by Aristotle (Chancellor) on Nov 12, 2005 at 22:34 UTC

    I strongly disagree.

    sub is_same_ref_str { $_[0] eq $_[1] } sub is_same_ref_num { $_[0] == $_[1] } $_ = \$_; print +( "not ", "" )[ is_same_ref_str( $_, "$_" ) ], "the same refere +nce\n"; print +( "not ", "" )[ is_same_ref_num( $_, "$_" ) ], "the same refere +nce\n"; __END__ the same reference not the same reference

    I use strict because I like not having to worry about stringified references. I compare them with == for the same reason; that protection is arguably weaker, but it’s still better than using eq.

    Of course, if you want to be really conscientous, you need to lug Scalar::Util into every script.

    Perl should have had eqref and neref operators to compare with reference semantics, the same way it has eq and ne to compare with string semantics vs == and != to compare with numeric semantics.

    Makeshifts last the longest.