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?

In reply to Use of $AUTOLOAD and strict by jira0004

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.