in reply to I know two prints are slower than one, but 200x slower?!?!?

if( $_ == $listener ){

I don't know if this is common practice and if it can cause false positives, nor whether == is overloaded, although the answer is: not that I know of. But unless all this holds, I would go with eq instead.

Replies are listed 'Best First'.
Re^2: I know two prints are slower than one, but 200x slower?!?!? (==)
by tye (Sage) on Aug 16, 2007 at 16:51 UTC

    If you know $x and $y are both objects, then I much prefer $x == $y over $x eq $y, your FUD not withstanding. If the objects may overload numification and/or stringification, then that changes things; it can make either or both of == / eq inappropriate. In that case, you can use something from overload but I'm not familiar with it.

    - tye        

      I think there's a function on recent versions of Scalar::Util, that returns the proper, unoverloaded reference, for use in Inside Out Objects for example.

      I guess it must be refaddr that is used for this.

        Indeed, overload says:

        overload::StrVal(arg)
        Gives string value of arg as in absence of stringify overloading. If you are using this to get the address of a reference (useful for checking if two references point to the same thing) then you may be better off using Scalar::Util::refaddr(), which is faster.

        - tye        

      If you know $x and $y are both objects, then I much prefer $x == $y over $x eq $y, your FUD not withstanding.

      Sorry for giving the impression of spreading FUD, which has a definitely bad acceptation. Actually it was a fear, an uncertainty and a doubt of mine, as I hope it was clear enough. Now, AIUI from your explanation, both == and eq are equally fine from the technical POV, aren't they?

      I must admit I had never thought what the numification of a (blessed) reference could be:

      cognac:~ [19:21:09]$ perl -le 'print for map {$_, 0+$_} bless \(my $x) +,"A"' A=SCALAR(0x814fe28) 135593512 cognac:~ [19:21:15]$ perl -le 'print 0x814fe28' 135593512

      Thank you for stimulating me to meditate and "experiment" about this!

      ...either or both of == / eq inappropriate. In that case, you can use something from overload but I'm not familiar with it.

      That would be overload::StrVal(), to be used with eq. Alternatively, Scalar::Util::refaddr() and ==.

      Update: All this has been said, as I noticed after posting.

      Anno