in reply to Re: Fill an array in a module ?
in thread Fill an array in a module ?

print MyModule::SharedArray[1]; # prints 2

Should be  $MyModule::SharedArray[1] The variable name still needs a sigil for full qualification.

In Perl, each module has its own namespace.

Each module can be given its own namespace (as shown in the code example via package) or, indeed, any namespace. It's not automatic.

Replies are listed 'Best First'.
Re^3: Fill an array in a module ?
by Anonymous Monk on Sep 14, 2014 at 05:18 UTC

    Each module can be given its own namespace (as shown in the code example via package) or, indeed, any namespace. It's not automatic.

    :) Yup its not automatic, but a "module" has a specific meaning:) A module is a namespace (package Foo) associated with a file (Foo.pm). A module is a package you can use or require. So if it doesn't do these things we usually don't call it a module :)

      It would be nice if "module" had a single, specific meaning throughout the world of Perl, but it doesn't. In my experience, it pretty much always means a .pm file, but that file may or may not contain a package and, if it does, the package may or may not have the same name as the file. A module usually contains a package of the same name, but not always.

        perlmod implies a module is supposed to be name.pm with a package name declaration, but like many things, "supposed to be" and "actually is" may not be the same.

Re^3: Fill an array in a module ?
by DarrenSol (Acolyte) on Sep 17, 2014 at 17:15 UTC

    Thanks for the reminder. I hadn't been using namespace qualifiers for these modules. I'd gotten away with that, somehow. But as the script set grows, it'll likely get cumbersome to have distinct names for arrays and variables.

    When I looked over the set I'd already scripted, it was obvious that some of those names were painfully long - and a fair number already included a kind of 'namespace' module abbreviation prefix in them.

    Yes, I was still scripting Saturday night...actually, until early Sunday morning. I used to try an alarm clock to remind me I should sleep at some point, but I just kept turning it off...