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

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        

  • Comment on Re^2: I know two prints are slower than one, but 200x slower?!?!? (==)

Replies are listed 'Best First'.
Re^3: I know two prints are slower than one, but 200x slower?!?!? (==)
by bart (Canon) on Aug 16, 2007 at 20:37 UTC
    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        

Re^3: I know two prints are slower than one, but 200x slower?!?!? (==)
by blazar (Canon) on Aug 16, 2007 at 17:24 UTC
    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!

Re^3: I know two prints are slower than one, but 200x slower?!?!? (==)
by Anno (Deacon) on Aug 17, 2007 at 15:37 UTC
    ...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