Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi Perl Monks
I posted this on Unix.com but haven't had a bite, so next stop here...
In my code, I know I can write...
if ( defined &test_sub ) { test_sub(); } else { print "Subroutine doesn't exist"; }
This tests the existence of the test_sub subroutine without actually calling it.
If, though, I replace test_sub with a package method...
I getif ( defined &$TEST->test_sub ) { TEST->test_sub; } else { print "Method doesn't exist"; }
Not a CODE reference at (eval 22)[/opt/perl/5.8.0/lib/perl5db.pl:17] l +ine 2, <STDIN> line 3.
Any suggestions what I'm doing wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to determine if a package method is defined
by almut (Canon) on Sep 30, 2009 at 22:54 UTC | |
by ikegami (Patriarch) on Oct 01, 2009 at 03:37 UTC | |
by almut (Canon) on Oct 01, 2009 at 03:58 UTC | |
by ikegami (Patriarch) on Oct 01, 2009 at 04:00 UTC | |
|
Re: How to determine if a package method is defined
by Your Mother (Archbishop) on Sep 30, 2009 at 23:16 UTC | |
|
Re: How to determine if a package method is defined
by Bloodnok (Vicar) on Sep 30, 2009 at 22:56 UTC | |
by almut (Canon) on Sep 30, 2009 at 23:06 UTC | |
|
Re: How to determine if a package method is defined
by jerryhone (Sexton) on Oct 01, 2009 at 07:55 UTC |