On Nov 28, 2007 6:15 PM, howa <[EMAIL PROTECTED]> 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?
>

My answer is: you can't.

See this test:

sub abc {
       print 'abc';
}

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

for (keys %::) {
    print "$_ -> $::{$_}\n" if /abc/;
}

__END__

the output is:
abcee -> *main::abcee
abc -> *main::abc

that's to say, when you say $f2 = \&abcee you have created an entry in
this script's symbol table. so, abcee can be anything (a hash, an
array, a scalar, a subroutine, a handler etc).
when and only when you call 'abcee' as a subroutine, perl can't find
the corresponding code substance, you have the chance to find the
error.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to