jira0004 has asked for the wisdom of the Perl Monks concerning the following question:
I am writing a Perl package that has an AUTOLOAD subroutine. I use strict in my package. In the AUTOLOAD subroutine I use $AUTOLOAD which according to Perl documentation is supposed to contain the name of the subroutine that Pelr couldn't find. Here is the source code:
sub AUTOLOAD { my $subroutine_name;<BR> $subroutine_name = $AUTOLOAD; }
According to Perl documentation, the mehod AUTOLOAD will automatically get called by Perl any time a method is invoked within the given package that Perl can not find. You can then use the AUTOLOAD method to find or define the given method. Alternatively in AUTOLOAD you could just report the problem, ignore it and keep going or trigger a die. The documentation indicates that $AUTOLOAD is a global variable in which Perl will place the fully qualified subroutine name that it can not find.
The problem I am having is that the code will not compile. It states that "Global symbol "$AUTOLOAD" requires explicit package name". Do I need to put the following at the start of my Perl script?
use vars qw ( $AUTOLOAD );Or is $AUTOLOAD supposed to be an automatic global variable that Perl should already know about?
I am a little confused. when I use strict I need to also use, "use vars qw ( @ISA );" if I want to use the @ISA array to set up inheritance, however, the list @INC and @ARGV are global variables that Perl already knows about and thus I do not need to use "use vars qw( @INC @ARGV);".
Any one know which special global variables Perl already knows about and which ones need to be explicitly stated using the "use vars qw ( ... ); " construct when the strict package is used?
I find it confusing that some special global variables require explicit declarations using "use vars qw ( ... ); " while others don't.
Any one have any useful input/feedback?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use of $AUTOLOAD and strict
by ikegami (Patriarch) on May 11, 2005 at 21:45 UTC | |
by ambrus (Abbot) on May 12, 2005 at 08:53 UTC | |
by ikegami (Patriarch) on May 12, 2005 at 13:39 UTC | |
by fizbin (Chaplain) on May 12, 2005 at 14:32 UTC | |
|
Re: Use of $AUTOLOAD and strict
by shemp (Deacon) on May 11, 2005 at 22:26 UTC | |
|
Re: Use of $AUTOLOAD and strict
by Tanktalus (Canon) on May 11, 2005 at 21:45 UTC | |
by ryantate (Friar) on May 11, 2005 at 23:34 UTC | |
by Tanktalus (Canon) on May 12, 2005 at 00:06 UTC | |
by ryantate (Friar) on May 13, 2005 at 21:52 UTC | |
|
Re: Use of $AUTOLOAD and strict
by rinceWind (Monsignor) on May 12, 2005 at 12:48 UTC |