in reply to Variable scope in packages.

BooYah.pm is only a package if you begin it with:
package BooYah;

Then, all vars in that package can be accessed as $BooYah::var_name.

Of course, you can have more than one package in a script :)

I think what you're asking is "what is the default package?". The answer to that is 'main' or '' by default.

The var would have to be declared globally (no my/local) and explicitly (you are using strict now, aren't you :). BUT, it's a bad idea to rely on vars in main from the package that was required. If you do though, there are two instances I can think of:

# (1) # Foo.pl - extract # implicitly %::crap = (turd => 'yellowy brown', crap => 'browny black'); # or explicitly %main::crap = (turd => 'yellowy brown', crap => 'browny black'); # BooYah.pm - extract require 'Foo.pl'; # implicitly print $::crap{turd}; # or, explicitly print $main::crap{turd}; # (2) - give Foo.pl a namespace # Foo.pl - extract package Foo; %Foo::crap = (turd => 'yellowy brown', crap => 'browny black'); # BooYah.pm - extract require 'Foo.pl'; print $Foo::crap{turd};

Although I'm a little worried about your question. Shouldn't you be requiring the module from the script and not requiring the script from the module?!?!

Do some research on namespaces, or read perlmod documentation.

cLive ;-)

Replies are listed 'Best First'.
Re: Re: Variable scope in packages.
by bikeNomad (Priest) on Jun 30, 2001 at 03:56 UTC
    Actually, you can have packages without using the 'package' keyword, by using fully-qualified names. The following defines things in three different packages (and is loadable as it stands as a module):

    sub A::A { } sub B::B { } $C::someVar = 123;