in reply to Undefined Subroutine errors
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Undefined Subroutine errors
by imp (Priest) on Jul 17, 2006 at 20:32 UTC | |
by Anonymous Monk on Jul 17, 2006 at 22:01 UTC | |
|
Re^2: Undefined Subroutine errors
by ikegami (Patriarch) on Jul 17, 2006 at 20:27 UTC |