|Do you know where your variables are?|
Compile Time Checking of Subroutine Calls is Possible After Allby sierrathedog04 (Hermit)
|on Jul 12, 2001 at 05:14 UTC||Need Help??|
sierrathedog04 has asked for the
wisdom of the Perl Monks concerning the following question:
Several weeks ago I asked my SOPW colleagues whether it would be possible for perl to check at compile time whether the named subroutines which I called actually existed. Several monks informed me that it was difficulty for perl to do so.
Thus, while mistyping a variable name always produces a compile-time error (assuming 'use strict' is on) mistyping a subroutine name only produced an error if at run-time the call to the non-existent subroutine actually occurred.
A recent posting by Tilly made me realize how to get compile time checking of my subroutine calls. Use anonymous subroutines.
It is all so easy. Here is a code snippet that shows how:
The above code fails at compile time because I mistyped the name of the subroutine reference. Call your subroutines using the above type of subroutine reference instead of subroutine name and you will never search for another typo in your subroutine calls again.
Named subroutines. Who needs 'em?