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 => \&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.

--
<http://www.dave.org.uk>

European Perl Conference - Sept 22/24 2000, ICA, London
<http://www.yapc.org/Europe/>