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

defined vs exists:

sub foo {} sub bar; my @names = qw( foo bar baz ); local $, = "\t"; local $\ = "\n"; print('', @names); print('exists', map { exists(&$_) ?1:0 } @names); print('defined', map { defined(&$_) ?1:0 } @names);
foo bar baz exists 1 1 0 defined 1 0 0

You can't call the ones that exist but aren't defined, so defined is probably a better choice.

>perl -e"sub bar; bar()" Undefined subroutine &main::bar called at -e line 1.

Replies are listed 'Best First'.