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



On Wed, Nov 28, 2007 at 02:15:39AM -0800, howa wrote:

sub abc {
print 'abc';
}

print "<", exists &abc, ">\n";
print "<", exists &abcee, ">\n";

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

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

print "<", defined &abc, ">\n";
print "<", defined &abcee, ">\n";

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

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

perldoc -f exists
perldoc -f defined

Note that a sub exists after taking a reference to it even though it
won't necessarily e defined.

--
Paul Johnson - paul@xxxxxxxx
http://www.pjcj.net
.



Relevant Pages

  • Re: local and my in subroutines
    ... The second sub in this script works using: ... perldoc -f getpwnam ... # Create extenions for log files as the older ones have a bz2 extension. ... foreach my $end { ...
    (perl.beginners)
  • RE: Why doesnt this work?
    ... Any time you don't understand a Perl function, look it up via perldoc. ... the shiftin the sub: ... Removes the first element of an array and stores it in $search. ...
    (perl.beginners)
  • Did not find leading dereferencer
    ... "Did not find leading dereferencer, ... join(' ', 'rcp', map(mk_remote_filename, @_)) ... where mk_remote_filename is a sub defined earlier, ... but when I check the perldoc for the function map, ...
    (comp.lang.perl.misc)
  • Re: Simple OO problem ...
    ... > sub copy ... This is very confusing code. ... perldoc -f bless ... perldoc perlstyle ...
    (perl.beginners)
  • Re: How to navigate the docs?
    ... >> What do you do when you want to find something in the Perl ... > provides the key to find full documentation with perldoc. ... the perldoc code looks much more ... sub get_pod_files { ...
    (comp.lang.perl.misc)