First, from perlsub
...if an AUTOLOAD subroutine is defined in the package or packages used to locate the original subroutine, then that AUTOLOAD subroutine is called with the arguments that would have been passed to the original subroutine. The fully qualified name of the original subroutine magically appears in the global $AUTOLOAD variable of the same package as the AUTOLOAD routine
My question has to do with the "magically appears in the global $AUTOLOAD variable of the same package as the AUTOLOAD routine" section.

If $AUTOLOAD is initialized by perl as a global in the package the routine is in, why must it be fully qualified or explicitly declared with our when used within that package when strict is in use.

# the following code throws a compile time error package TestPackage; use strict; sub AUTOLOAD { print $AUTOLOAD, " is not available\n"; } # this code is fine package TestPackage; use strict; our $AUTOLOAD; # 'use vars qw( $AUTOLOAD )' works too sub AUTOLOAD { print $AUTOLOAD, " is not available\n"; }
This error:
Global symbol "$AUTOLOAD" requires explicit package name
seems to make a liar out of perlsub. I get from the docs that $AUTOLOAD will be set to be a part of the package the routine is in, but it doesn't seem to behave that way.

I'm sure I've misinterpreted, but I just don't see where.




Amel

In reply to Fully qualifying $AUTOLOAD by dsb

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.