Re: How to check if a function reference is valid or not?



On Wednesday 28 November 2007 02:15, howa wrote:

sub abc {
print 'abc';
}

my $f1 = \&abc;
my $f2 = \&abcee;

print $f1; # return CODE(0x..)
print $f2; # also return CODE(0x..)

$f1->();
$f2->();

How do I know if $f2 is a valid function reference, without actual
calling it?


$ perl -le'
sub abc {
print 'abc';
}

my $f1 = \&abc;
my $f2 = \&abcee;

print "\$f1 ", defined &$f1 ? "exists" : "does not exist";
print "\$f2 ", defined &$f2 ? "exists" : "does not exist";

$f1->();
$f2->();
'
$f1 exists
$f2 does not exist
Undefined subroutine &main::abcee called at -e line 13.



John
--
use Perl;
program
fulfillment
.