mgraham ([EMAIL PROTECTED]) said something to this effect:
> 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.

Sharing a variable among children is difficult; you need to use IPC::Sharable
or something similar. There is an example in the Apache::Session perldocs of
using a "session" to store global data that gets shared among the children
as well.

The problem with sharing stuff between the parent and children, if I
understand it correctly, is that once a child forks, it has a copy of the
variable, not a reference to it. So, modifications to this copy affect that
child only.

I've never gotten the shm version to work, but I have gotten the
Apache::Session version to work. This is straight from the perldoc:

    use Apache;
    use Apache::Session::File;
    use DBI;

    use strict;

    my %global_data;

    eval {
        tie %global_data, 'Apache::Session::File', 1,
           {Directory => '/tmp/sessiondata'};
    };
    if ($@) {
       die "Global data is not accessible: $@";
    }

    my $dbh = DBI->connect($global_data{datasource},
       $global_data{username}, $global_data{password}) || die $DBI::errstr;

    undef %global_data;

    #program continues...

Pretty useful stuff.

(darren)

-- 
I'd rather have my own game show than enough votes to become president.

Reply via email to