difference between namespace and module?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manimarank
    New Member
    • Jul 2007
    • 23

    difference between namespace and module?

    what is the difference between namespace and module?
    can anyone help me briefly..
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by manimarank
    what is the difference between namespace and module?
    can anyone help me briefly..
    Ok, I am going to give you my take on this, but am sure that someone like Miller or KevinADC will be able to add more to this, even possibly links to better explanations.

    A module is basically a set of subroutines that are designed to do a specific set of tasks, all with a common goal/topic. You "use" modules in your Perl code and once you do, their functions are available to you.

    Now, say you have two modules that end up having two functions with the same name, but do two completely different things. You need to be able to tell them apart. That is where the module, acts like a namespace.

    For example, if modules "My::First::Mod ule" and "My::Second::Mo dule" both have a function called "Count()", but you need the version from "My::First::Mod ule", then you would specify that when you called the function, like so:

    My::First::Modu le::Count(optio ns)
    {
    some code;
    }

    Ok, that is my take on this topic. Short and sweet. Hopefully, if there is more, and I am sure there is, that someone will enlighten not only you, but me as well.

    Regards,

    Jeff

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      just think of the namespaces as boxes or compartments where all the stuff related to a module or your main program are kept. Jeffs explanation seems good enough, it can be extended to include data types too (and some other stuff), so things like:

      $foo
      @foo
      &foo
      foo()
      *foo

      when used in the same package/namespace are kept seperate.

      Comment

      Working...