in reply to Comparing references to sub's

Actually after a lot of playing around I got the references to match - but the question is still valid - is comparing ref's to subroutines valid/appropriate (or any reference for that matter), or am I playing a little to close to Perl internals, (the fact that it works in 5.6 may change in 5.8 or 6.0, etc)?

Replies are listed 'Best First'.
Re^2: Comparing references to sub's
by diotalevi (Canon) on Mar 20, 2003 at 01:51 UTC
Re: Re: Comparing references to sub's
by graff (Chancellor) on Mar 20, 2003 at 02:00 UTC
    Comparing references is a stable and well-defined operation:
    if ( $thisref eq $thatref ) { # these are two refs address the same object, whatever it is }
    (update: as diotalevi has pointed out, the "==" comparison would be more efficient that the "eq", but otherwise the results are equivalent.)

      If you want to be really sure you should use refaddr from Scalar::Util since the reference type could overload any of eq, ==, "" or 0+.

      Obviously not necessary in this case, but not doing it can catch you out (well, it's caught me out before) if you add overloading at a later date.