On Sun, Mar 15, 2009 at 22:33, <practicalp...@gmail.com> wrote: > Hello, > > How to find there're one or more undefined subroutines in a perl scritp? > for example, snip
I don't think you are going to like this, but the answer is 100% code coverage testing. Because Perl is a dynamic language, functions can be created at any time. This means there is no safe way of determining if a function exists by static analysis of source code. The only way to find out is to let perl run the code*. What is worse, you can wind up in situations like this if ($foo) { *bar = sub { print "I created bar() because \$foo was set\n" }; } bar(); If $foo is true then the bar function gets created and there is no error, if $foo is false then the bar function does not exist and an "Undefined subroutine" error is thrown. This means if you want to be certain that you Perl program is correct you must test it in a way that exercises every code path. There are tools to help you do this such as Devel::Cover**. There may be modules that will take a stab at finding undefined subroutines, but they will return many false positives and possibly some false negatives: sub bar { print "bar exists\n" }; undef *bar; #no it doesn't bar(); #error That code would be hard to catch by static analysis. * this is a restatement of a classic Perl saying: only perl can parse Perl*** ** http://search.cpan.org/dist/Devel-Cover/lib/Devel/Cover.pm *** which is just a restatement of the Halting Problem*** from Computer Science **** http://en.wikipedia.org/wiki/Halting_Problem -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/