in reply to Re^3: Where and when you should place 'use module;'?
in thread Where and when you should place 'use module;'?

I clearly state that it is the import portion of use that is scoped to the package, so I didn't think that it was misleading, but thank you for clarifying. My key point was that no aspect of a use module is file scoped, as the upthread post claimed.

I see your point with respect to package scope, but I disagree. Scope means the area in which the symbols are immediately available and immediately effected - the current context or 'view'. In your example, the scope of an rm * is the CWD. If you cd to another directory, the scope changes, but the old scope isn't destroyed forever, it is just one step removed from the action.

This is the difference between scope and extent. Lexicals have a dynamic extent - they persist only as long as you keep a window on that scope open. Package variables have limited scope but unlimited extent.

Replies are listed 'Best First'.
Re^5: Where and when you should place 'use module;'?
by Moron (Curate) on Oct 12, 2005 at 15:01 UTC
    It is file scoped if it is not used within a package -- I tested this.

    -M

    Free your mind

      It is file scoped if it is not used within a package -- I tested this.

      That doesn't make any sense. You're almost always within a package. Can you show us how you tested this?

      Update: added clarification. Thanks Perl Mouse!

        You're always within a package.
        No, you are not.
        package; print __PACKAGE__; __END__ Use of "package" with no arguments is deprecated at ... Use of uninitialized value in print at ...
        From perldoc -f package:
        If NAMESPACE is omitted, then there is no current package, and all identifiers must be fully qualified or lexicals. However, you are strongly advised not to make use of this feature. Its use can cause unexpected behaviour, even crashing some versions of Perl. It is deprecated, and will be removed from a future release.
        Although you shouldn't, you can be outside of any package.
        Perl --((8:>*
        Well, I wasn't counting &main as a package - it certainly wasn't explicitly declared as one.

        -M

        Free your mind

      Can you show us how you tested this? I think that you are mistaken. The term 'file scoped' only makes sense with respect to lexical scopes in Perl, and import doesn't have access to the caller's lexical scope unless you play around with something like PadWalker.

      Here is a counter example:

      ## file one.pl: use strict; use warnings; use Data::Dumper; require "./two.pl"; ## file two.pl: print Dumper [1,2,3]; ## output: $VAR1 = [ 1, 2, 3 ];
        ++ for thinking of require as a counter-example.

        -M

        Free your mind