in reply to Validating a Code Reference
Thanks everyone for your help, but I think I've got a solution - and it's even simpler than I hoped for. Take a look at this:
sub there { print "I'm here!"; } my %refs = (there => \&there, not => \¬_there, anon => sub { "I'm here too!" }); foreach (keys %refs) { print "'$_' is ", defined &{$refs{$_}} ? "valid\n" : "invalid\n"; }
Which displays:
'there' is valid 'not' is invalid 'anon' is valid
Much kudos to Matt Freake of London.pm for coming up with the solution - defined &$coderef.
--
|
|---|