From: "Chas. Owens" <chas.ow...@gmail.com>
> On Wed, Mar 25, 2009 at 00:03, Chap Harrison <c...@pobox.com> wrote:
> > Hi again,
> >
> > I'm trying to factor out the declaration and setting of a bunch of variables
> > that a suite of programs will need, as well as defining some subroutines
> > that will be needed.  I've been mainly referencing Programming Perl 5, but I
> > am mighty confused at this point.
> >
> > I'm particularly confused about how variables that are declared in my
> > Package manage to become visible to main (although that's exactly what I
> > want to happen).  As well as the whole issue of what happens when (at BEGIN,
> > at use, etc.).  I feel sure I've greatly complicated things; as I say, all I
> > want is a way to initialize a handful of "global" variables, and provide a
> > few subroutines.
>
> You need to add the variables you want exported to either @EXPORT (the
> mandatory list of things to export) or @EXPORT_OK (this list of things
> to export on demand).

No. @EXPORT specifies the default list, not mandatory.

> > This one baffles me.  I still have to explicitly export $g_database_path by
> > putting it into @EXPORT - what is 'our' doing that 'my' doesn't?
> snip
>
> our and my both create variables.  The difference is their scope and their
> interaction with packages.

Again. No. "my $foo" does create a brand new scalar variable named
foo in the current lexical scope. "our $foo" doesn't create any
variable at all. All it does is that it tells "use strict" that you
are aware of the scalar variable foo in the current package and want
to be allowed to access it using just the short name.

Without "use strict" you can actually use any variable in the current
package using just the short name, even without notifying Perl that
you will want to by using "our" or "use vars".

Jenda
===== je...@krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to