in reply to How to check if a function exists within a package?

I prefer a symbol table lookup.
perl -e ' package Foo; sub bar{42}; package main; print defined *Foo::bar{CODE}' 1
This avoids ambiguity issues with using the ampersand.

print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});

Replies are listed 'Best First'.
Re^2: How to check if a function exists within a package?
by Anonymous Monk on Jan 22, 2009 at 18:16 UTC
    why not: sub method_exists_in_obj($$) { my $obj = shift;#object as href my $method = shift;#method name to test for return 1 if (defined(&{(ref $obj)."::".$method})); return 0; }