Hi,
The mod_perl website tells us that modules can pre-define package global variables at server startup time and have the data be shared by child processes:
http://perl.apache.org/guide/porting.html#Sharing_variables_between_proces
>* Global variables initialized at the server startup, through
>the Perl startup file, can be shared between processes, until
>modified by some of the processes. e.g. when you write:
> $My::debug = 1;
>
>all processes will read the same value. If one of the processes
>changes that value to 0, it will still be equal to 1 for any other
>process, but not for the one which actually made the change. When a
>process modifies a shared variable, it becomes the process' private
>copy.
Is the same true for file-scoped "my" variables?
I'd like to create an object that stores some big read-only data in a file-scoped "my" variable:
package ThisObject;
my $BigPrivateReadOnlyData;
BEGIN
{
$BigPrivateReadOnlyData = `cat somebigfile.txt`; ## for example.
}
sub MyMethod
{
my $this = shift;
my $DataCopy = $BigPrivateReadOnlyData;
# etc.
}
My guess is that "my $Big..." should work just as well as "$My::Big...".
Does it?
--------
ANOTHER QUESTION ABOUT SHARED VARIABLES:
What happens if I do pattern-matching that might modify the pos() of a scalar that's been shared?
For example:
my $FoodCount = ($BigPrivateReadOnlyData =~ m/dog: (food)/g);
Does modifying the pos() of a shared variable make the variable unshared?
--------
Thanks in advance to the person who knows the answer to these imponderables.
-chris
------------------------------------------------------------------------
870 Market Street #1270 (415) 394-9818
San Francisco, CA 94102 (413) 473-0853 fax
------------------------------------------------------------------------
The mod_perl website tells us that modules can pre-define package global variables at server startup time and have the data be shared by child processes:
http://perl.apache.org/guide/porting.html#Sharing_variables_between_proces
>* Global variables initialized at the server startup, through
>the Perl startup file, can be shared between processes, until
>modified by some of the processes. e.g. when you write:
> $My::debug = 1;
>
>all processes will read the same value. If one of the processes
>changes that value to 0, it will still be equal to 1 for any other
>process, but not for the one which actually made the change. When a
>process modifies a shared variable, it becomes the process' private
>copy.
Is the same true for file-scoped "my" variables?
I'd like to create an object that stores some big read-only data in a file-scoped "my" variable:
package ThisObject;
my $BigPrivateReadOnlyData;
BEGIN
{
$BigPrivateReadOnlyData = `cat somebigfile.txt`; ## for example.
}
sub MyMethod
{
my $this = shift;
my $DataCopy = $BigPrivateReadOnlyData;
# etc.
}
My guess is that "my $Big..." should work just as well as "$My::Big...".
Does it?
--------
ANOTHER QUESTION ABOUT SHARED VARIABLES:
What happens if I do pattern-matching that might modify the pos() of a scalar that's been shared?
For example:
my $FoodCount = ($BigPrivateReadOnlyData =~ m/dog: (food)/g);
Does modifying the pos() of a shared variable make the variable unshared?
--------
Thanks in advance to the person who knows the answer to these imponderables.
-chris
------------------------------------------------------------------------
870 Market Street #1270 (415) 394-9818
San Francisco, CA 94102 (413) 473-0853 fax
------------------------------------------------------------------------