ianyappy has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: say statements within 'sub AUTOLOAD'
by Anonymous Monk on Dec 25, 2010 at 10:38 UTC | |
by ianyappy (Initiate) on Dec 25, 2010 at 17:22 UTC | |
by AnomalousMonk (Archbishop) on Dec 25, 2010 at 19:26 UTC | |
by ianyappy (Initiate) on Dec 26, 2010 at 03:04 UTC | |
by Anonymous Monk on Dec 25, 2010 at 18:23 UTC |