in reply to Detect undefined subroutines

Not without completely changing how you code in a way that will annoy everyone else.

If you're willing to do that then never call routines directly, instead do them through variables...

#!/usr/bin/perl use strict; use warnings; my $fooz = sub { print "Hello, world\n"; }; $foo->();
And now -c catches the error.

The solution is ugly enough that everyone I know is willing to just live with the problem instead.

Replies are listed 'Best First'.
Re^2: Detect undefined subroutines
by ihb (Deacon) on Sep 18, 2004 at 16:51 UTC

    You could use

    sub foo { ... } *foo->(...);
    to receive compile-time warnings, assuming you don't use any other global datatype called foo (and doesn't try to call the same undefined subroutine twice).

    Update: boldened "warnings" and added parenthesis.

    ihb

    Read argumentation in its context!

      Interesting idea, but it doesn't seem to work.
      tilly@(none):~$ perl -ce 'use strict; *foo->()' -e syntax OK tilly@(none):~$ perl -e 'use strict; *foo->()' Undefined subroutine &main::foo called at -e line 1.
      Tested with Perl 5.8.4.

      UPDATE I see, my oversight.

        You need to turn on warning to see them...

        $ perl -Mstrict -cwe '*foo->()' Name "main::foo" used only once: possible typo at -e line 1. -e syntax OK $ perl -Mstrict -we '*foo->()' Name "main::foo" used only once: possible typo at -e line 1. Undefined subroutine &main::foo called at -e line 1.

        ihb

        Read argumentation in its context!