question about namespacing in perl

  • Thread starter Khamis Abuelkomboz
  • Start date
K

Khamis Abuelkomboz

Hi

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.

thanks
khamis

--
Try Code-Navigator on http://www.codenav.com
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
* PHP, HTML, XML, ASP, CSS
* Tcl/Tk,
* Perl
* Python
* SQL,
* m4 Preprocessor
* Cobol
 
T

Tassilo v. Parseval

Also sprach Khamis Abuelkomboz:
I'm trying to unterstand the namescoping of perl, I found the following example:

package B::Assembler;
...
sub B::Asmdata::pUT_U8 {..}

This is the function PUT_U8() living in the package (=namespace)
B::Asmdata.
How do you define the full namespaced sub name?
Is it B::Assembler::B::Asmdata::pUT_U8 or only B::Asmdata::pUT_U8 ?

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.
How you would call the function PUT_U8 from outside and inside this package?

From outside:

B::Asmdata::pUT_U8()

From inside:

PUT_U8()
# or (although unnecessarily)
B::Asmdata::pUT_U8()

Note that giving the full name works everywhere whereas accessing an
unqualified entry only works if that entry lives in the current
namespace.
I think the subs following a package definition belong to this package.

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 {}

Tassilo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top