in reply to How do I test the validity of a CODE reference?
You can't tell if a code ref actually has code behind it that way. \&anyNameHere will return an apparently valid code ref. The only way is to actually invoke it, so do the invocation within an eval block:
print $_, ':', eval{ $_->(); 1 } ? "S'ok" : "Uht erd!" for sub{ print 'good code' }, \&doesNotExist;; good code CODE(0x194a9b4) : S'ok CODE(0x194a954) : Uht erd!
|
|---|