http://www.perlmonks.org?node_id=95899

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:

use strict; my $flag = shift; my $hello = (sub { return "hello by reference\n";}); print $xello->() if $flag;
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?