in reply to basic conception?

To answer your first question: a namespace is the "space" in which identifiers corresponding to a program are stored. These identifiers include variable names, subroutine names, file handle names, and mostly anything that you can refer to by name in a Perl program (or in any other, the concept is not exclusive to Perl).

The main reason to be aware of namespaces is that you cannot have two things of the same type with the same name in the same namespace, but you can do that if they are in different namespaces. For example, each package in Perl defines a new namespace, which is why different packages can have variables with the same name and not have them conflict with each other. In perl, the fully qualified name of a variable or a subroutine is given by prepending its package name separated by two colons. So for example, if both packages A and B define a variable v, they are actually two different variables, with the full names $A::v and $B::v.

Replies are listed 'Best First'.
RE: Re: basic conception?
by turnstep (Parson) on Apr 25, 2000 at 21:42 UTC
    Even variables that you do not declare to be in any package are by default in the "mother of all packages", main. So when you write "$x=10;" perl really sees it as
    $main::x=10;

    Since everything is based off of main, the examples above can also be written as:

    $main::A::v and $main::B::v
    (Both ways are 'correct', although the previous way is actually preferred.)

    Unless you are creating your own packages, you don't have to worry about namespace or about using the double colon identifier - perl does all of that behind your back. But it is a nice feeling to know that perl is back there, keeping track of everything for you. :)