in reply to Re: Lexical and dynamic scope confusion!
in thread Lexical and dynamic scope confusion!

my understanding was that, and please do correct me if i'm wrong, when i say "use CGI" in my code, it exports everything that was specified in "@EXPORT_OK" list in the CGI.pm module. if sub1 is one of them, then it is imported into my program's symbol table even though i do not know of its existence (ofcourse, i can find out all the functions and varibles imported through 'use')
back to the original question, if i declare and define a sub called sub1 and call it within my program, (again the function calls would be identical too as i don't have to fully qualify calls to subroutines that reside in the package that i import as long as it is imported through 'use package-name') which one is it referring to? how does CGI.pm module ensure that a call to sub1 is answered by it and not the one in my code? or does it even check for such a thing?
  • Comment on Re^2: Lexical and dynamic scope confusion!

Replies are listed 'Best First'.
Re^3: Lexical and dynamic scope confusion!
by Zaxo (Archbishop) on Mar 27, 2005 at 06:15 UTC

    No, you're thinking of @EXPORT. Names in @EXPORT_OK are exported only if asked for, by convention.

    CGI uses its own custom import routine instead of subclassing Exporter, but as far as I know it follows the perl conventions on this.

    If sub1() is in @EXPORT, then it is indeed imported to the namespace where use CGI; appears. In that case, the last-defined version is the one which is called (along with a redefinition warning).

    use CGI; sub sub1 {} # this one overwrites CGI's
    but,
    sub sub1 {} use CGI; # CGI's overwrites yours

    After Compline,
    Zaxo