http://www.perlmonks.org?node_id=189485

twerq has asked for the wisdom of the Perl Monks concerning the following question:

Just a quick question -- what's the best (eg. fastest, least amount of code) way to test to see if a subroutine is defined in the current namespace?

I looked around here a bit, but couldn't find anyone else's comments on this. So I've been using eval, but I figure there must a perl shortcut for this sort of thing..

Here's what I've got:
my $sub_to_test = "test_sub"; # try to fire an EVAL_ERROR eval "$sub_to_test()"; # if no EVAL_ERROR if (!$@) { # do the thing eval "$sub_to_test ('testing, 1,2,3')"; } sub test_sub { return unless @_; print "TEST_SUB: $_[0]\n"; }

can I do any better?
--twerq