question about namespacing in perl

Discussion in 'Perl Misc' started by Khamis Abuelkomboz, May 2, 2005.

  1. 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
     
    Khamis Abuelkomboz, May 2, 2005
    #1
    1. Advertising

  2. 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
    --
    use bigint;
    $n=71423350343770280161397026330337371139054411854220053437565440;
    $m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
     
    Tassilo v. Parseval, May 2, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KC

    Proper namespacing

    KC, Feb 8, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    364
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Feb 8, 2005
  2. =?Utf-8?B?ZGFGb3U=?=

    How to register an HTTPhandler with custom namespacing

    =?Utf-8?B?ZGFGb3U=?=, Nov 16, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    461
    =?Utf-8?B?ZGFGb3U=?=
    Nov 16, 2005
  3. Zouplaz

    Namespacing my classes

    Zouplaz, Oct 13, 2008, in forum: Ruby
    Replies:
    7
    Views:
    99
    Robert Klemme
    Oct 14, 2008
  4. Dan Webb

    Packaging / Namespacing JavaScript

    Dan Webb, Jul 13, 2004, in forum: Javascript
    Replies:
    6
    Views:
    147
    Richard Cornford
    Jul 15, 2004
  5. Peter Michaux

    pseudo-namespacing in JavaScript

    Peter Michaux, Feb 22, 2008, in forum: Javascript
    Replies:
    14
    Views:
    370
    dhtml
    Feb 25, 2008
Loading...

Share This Page