it's quite likely that the OP should have been using exists and that can will do the trick by itself.
Well, depends on whether this is the desired result...
#!/usr/bin/perl $TEST = "foo"; if ( $TEST->can("test_sub") ) { $TEST->test_sub; } else { print "Method doesn't exist"; } package foo; sub test_sub; __END__ Undefined subroutine &foo::test_sub called at ./798474.pl line 6.
And if the method was defined (likely, in real life, if it's there at all), the difference between defined and exists wouldn't matter (which is why I skipped that part and focused on the inheritance aspect). In other words, I'd say in practical terms the difference between defined and exists is mostly irrelevant (after all, why would people declare bodiless subs in their packages), but if you want to be sure a method can actually be called, then do test whether it's defined...
In reply to Re^3: How to determine if a package method is defined
by almut
in thread How to determine if a package method is defined
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |