in reply to Benefiting from Devel::Profile or Devel::FastProf
I am confused about one thing still. Was the AUTOLOAD caused because my code called an undefined subroutine?
Yes. But that isn't your fault. If a perl package tells you that you can call a certain method, then you can call it. How the package handles that method call is another matter. The package developer may define the method, or he may omit the method and define a method named AUTOLOAD to handle the method call. Letting AUTOLOAD handle the method call is less efficient but it can be much more flexible.
=====use strict; use warnings; use 5.010; sub AUTOLOAD { our $AUTOLOAD; say "A method named $AUTOLOAD was called."; return 10; } my $result = calculate(); say $result; --output:-- A method named main::calculate was called. 10
use strict; use warnings; use 5.010; sub AUTOLOAD { our $AUTOLOAD; my (undef, $greeting) = split '_', $AUTOLOAD; say $greeting; } say_goodbye(); say_hello(); --output:-- goodbye hello
|
|---|