in reply to defined &{ $pkg . '::foo' } vs. $pkg->can( 'foo' )

$ perl -w sub foo; sub AUTOLOAD { print "called $AUTOLOAD" } print "is foo defined? ",0+defined &foo, " does foo exist? ", 0+exists + &foo, "\n"; foo(); __END__ is foo defined? 0 does foo exist? 1 called main::foo
You almost always want to use exists &subname rather than defined &subname; there's no advantage in excluding declared-but-not-defined subs.

Replies are listed 'Best First'.
Re^2: defined &{ $pkg . '::foo' } vs. $pkg->can( 'foo' )
by tlm (Prior) on Jul 15, 2005 at 12:56 UTC

    You almost always want to use exists &subname rather than defined &subname; there's no advantage in excluding declared-but-not-defined subs.

    Hmmm... I don't see how including declared-but-not-defined subs could be a good idea either for the particular application I had in mind or for the one I cited.

    the lowliest monk

      I don't see why. Pre-declaring subs is the responsible way to use AUTOLOAD. Why would you want to disallow it in your delegatees? Anyway, this qualifies as a difference between ->can and defined&.

        Pre-declaring subs is the responsible way to use AUTOLOAD.

        I wasn't aware of this convention. Good to know. Thanks.

        the lowliest monk