darren chamberlain wrote:
> ...Except that by calling Foo:load_var() you are setting
> $PACKAGE_LEXICAL
> to undef (by passing in an empty list via ()), rather than
> retrieving it.

Well, actually, I was checking to see if it was set first:

    sub load_var {
        my $param = shift;
        $PACKAGE_LEXICAL = $param if $param;
    }

Your example does essentially the same thing, but is interesting
because it puts the sub and the lexical variable in a nested block
scope, and as you say:

> Each child will have its own $PACKAGE_LEXICAL.

That's a neat trick!  However, for my purposes, I don't want each
child to have a separate $PACKAGE_LEXICAL.  I want to set the variable
with the parent process (actually from setup.pl) and I want children
to be able to call the sub without any parameters.  And I want the
variable to be visible to subs in the same package, but not to code
outside the package.  It's kind of like a class variable without
objects.  Maybe it would be clearer with two subs:

    package Foo;
    my $PACKAGE_LEXICAL;
    sub set_var {
        $PACKAGE_LEXICAL = shift;
    }
    sub do_stuff {
        # do something with $PACKAGE_LEXICAL;
    }

I want to be able to call Foo::set_var('wubba') from startup.pl, and
then call Foo::do_stuff() from some child process.

The weird thing is, this works as I expect when I put "PerlModule Foo"
in httpd.conf, but not when I put "use Foo;" in startup.pl.

Does everybody else use PerlModule to pull in their modules, or
startup.pl?

Michael


Reply via email to