There are several reasons why undefined functions are not caught at compile time, here are a few:
Autoloading
See AUTOLOAD in the perlsub document.
Conditional calling of functions
In the above example somefunction is only called if the passed object has this method defined.sub test { my $object = shift; $object->somefunction if $object->can('somefunction'); }
This is useful when you might have different objects being used that conform to a common interface, but have some additional capabilities.
Also useful when you might be dealing with older versions of a module that do not support certain methods.
Checking if an object can do something is generally preferrable to checking if an object is something
In reply to Re: Undefined Subroutine errors
by imp
in thread Undefined Subroutine errors
by enemyofthestate
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |