question about namespacing in perl

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I'm trying to unterstand the namescoping of perl, I found the following example:

package B::Assembler;
sub B::Asmdata::PUT_U8

How do you define the full namespaced sub name?
Is it B::Assembler::B::Asmdata::PUT_U8 or only B::Asmdata::PUT_U8 ?
How you would call the function PUT_U8 from outside and inside this package?

I think the subs following a package definition belong to this package.


Try Code-Navigator on
a source code navigating, analysis and developing tool.
It supports following languages:
     * C/C++
     * Java
     * .NET (including CSharp, VB.Net and other .NET components)
     * Classic Visual Basic
     * Tcl/Tk,
     * Perl
     * Python
     * SQL,
     * m4 Preprocessor
     * Cobol

Re: question about namespacing in perl

Also sprach Khamis Abuelkomboz:

Quoted text here. Click to load it

This is the function PUT_U8() living in the package (=namespace)

Quoted text here. Click to load it

It's the latter. Specifying namespaces can only ever happen in two ways:
Either unqualified (PUT_U8()) which will access the entry in the current
namespace (main:: if there is no explicit package-declaration) or fully
qualified (B::Asmdata::PUT_U8()) which accesses the entry in B::Asmdata
regardless of the namespace the calling code lives in.

Quoted text here. Click to load it

From outside:


From inside:

    # or (although unnecessarily)

Note that giving the full name works everywhere whereas accessing an
unqualified entry only works if that entry lives in the current

Quoted text here. Click to load it

Yes, as long as they are not qualified. In your example above however
the package-declaration was overruled by the package-declaration in

    sub B::Asmdata::PUT_U8 {}

use bigint;

Site Timeline