You don't need eval and you can just inspect the main namespace for whether a subroutine of that name is defined:
use strict; use Data::Dumper; sub foo { print "foo\n"; } for my $subname (@ARGV) { my $glob = $::{$subname}; warn defined $glob ? "'*$subname' exists" : "'*$subname' not found"; if ($glob) { my $sub = *{$glob}{CODE}; warn defined $sub ? "'$subname' exists" : "'$subname' not found"; &$sub if $sub }; }
In reply to Re: How do I test the validity of a CODE reference?
by Corion
in thread How do I test the validity of a CODE reference?
by pilap
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |