I'm a newbie trying out the AUTOLOAD subroutine.. I can't figure out why the say statement does not work when AUTOLOAD is invoked? Appreciate any help
{ package MyDate; sub AUTOLOAD { our $AUTOLOAD; say "Going into AUTOLOAD"; # Why doesn't this print? my $method = $AUTOLOAD; $method =~ s/.*:://; grep {$method eq $_} qw/yak day month/ or Carp::croak "Invalid + method: $method."; if ($method eq "day") { eval { sub day {(localtime)[3];} }; } elsif ($method eq "month") { eval { sub month {(localtime)[4] + 1;} }; } Carp::croak $@ if $@; goto &$method; } } ###################################################################### +################## say MyDate->day; say MyDate->month;
The output is just
25 12
In reply to say statements within 'sub AUTOLOAD' by ianyappy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |