B
Bill H
In many of my programs I use require as a sort of conditional include
to use code only when needed. I have noticed that if a "required"
program also has a "require" in it that the 2nd one does not have
access to the variables from the first, but does have access to the
variables from the main code. Is this normal or am I doing something
wrong? Here is a rough example on how I am using it:
Main program
require "global.pm"; # These are global routines used by everything
if ($var == 1)
{
require "subprog.pm";
}
Subprog.pm
$page = "index.htm";
&SendPage($page); # this is a routine in global.pm to load and display
the file named in $page
The above will work fine, but if I do this:
Subprog.pm
$page = "index.htm"
if ($page eq "index.htm")
{
require "subprog2.pm";
}
Subprog2.pm
&SendPage($page);
Subprog2.pm does not get the value for $page passed to it by
Subprog,pm.
I know this is rough but I hope it illustrates the idea. There is
probably something simple I am not doing but I have not been able to
figure out how to get a required program to allow its variables to be
accessed by another one. Am i right in assuming that code that is
included using "require" just gets "run" in the place where the require
is at (similar to using #include in C), or is it run as a form of
subroutine?
Bill H www.ts1000.us
to use code only when needed. I have noticed that if a "required"
program also has a "require" in it that the 2nd one does not have
access to the variables from the first, but does have access to the
variables from the main code. Is this normal or am I doing something
wrong? Here is a rough example on how I am using it:
Main program
require "global.pm"; # These are global routines used by everything
if ($var == 1)
{
require "subprog.pm";
}
Subprog.pm
$page = "index.htm";
&SendPage($page); # this is a routine in global.pm to load and display
the file named in $page
The above will work fine, but if I do this:
Subprog.pm
$page = "index.htm"
if ($page eq "index.htm")
{
require "subprog2.pm";
}
Subprog2.pm
&SendPage($page);
Subprog2.pm does not get the value for $page passed to it by
Subprog,pm.
I know this is rough but I hope it illustrates the idea. There is
probably something simple I am not doing but I have not been able to
figure out how to get a required program to allow its variables to be
accessed by another one. Am i right in assuming that code that is
included using "require" just gets "run" in the place where the require
is at (similar to using #include in C), or is it run as a form of
subroutine?
Bill H www.ts1000.us