in reply to Possible to catch undefined sub at "compile" time?

It would be nice if the typo ("mink") was caught ... at compile-time

<flippancy>

Assuming your script is actually going to call the go subroutine, your requirement would be satisfied by running the entire script inside a BEGIN{} block:
BEGIN { use warnings; use strict; use 5.008; go(); sub monk {} sub go { mink(123); } }; print "After compilation, this message appears\n"; __END__ Outputs: Undefined subroutine &main::mink called at try.pl line 9. BEGIN failed--compilation aborted at try.pl line 11.
</flippancy>

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Possible to catch undefined sub at "compile" time?
by shmem (Chancellor) on Oct 10, 2007 at 13:01 UTC
    Cheater!
    Code in BEGIN blocks gets compiled and run, so the "Undefined ..." message is a really a runtime error :-)

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      And the print "After compilation, this message appears\n"; that never gets executed .... that must be post-runtime code :-)

      You're right, of course - the <flippancy> tags could just as well (or better) be replaced with <cheat> tags.

      Cheers,
      Rob