Please only post to one group, if that group does not yield a good
answer, then try a different one. Especially since this has nothing to
do with CGI.


> Can anyone tell me why this code fails when trying to load
> Some_Module_In_lib_Dir-
> ==============================
> my $file_path =
> substr($ENV{SCRIPT_FILENAME},0,index($ENV{SCRIPT_FILENAME},'/test.cgi'));

The above happens at runtime, 

> use lib "$file_path/../lib";

The above happens at compile time, so $file_path is empty (at least I
suspect).

> use Some_Module_In_lib_Dir;
> 
> ==============================
> And this code does not -
> ==============================
> use FindBin qw($Bin);

This is loaded at compile time and I suspect it sets $Bin at compile time,

> use lib "$Bin/../lib";

This is then loaded at compile time with $Bin already having been set.

> use Some_Module_In_lib_Dir;
> 
> ==============================
> And this code does not -
> ==============================
> use lib '/home/user/domain-www/cgi-bin/some_dir/test/../lib'

Obviously this is hardcoded and loaded at compile time. Since it is just
a string it works.

> use Some_Module_In_lib_Dir;
> 
> ==============================
> And this code does not -
> ==============================
> use lib
> substr($ENV{SCRIPT_FILENAME},0,index($ENV{SCRIPT_FILENAME},'/test.cgi')) .
> "/../lib";

This is impressive, but I suspect Perl is loading the whole statement at
compile time, and since the %ENV is already established it works. I am
impressed (but not terribly surprised, Perl is so cool) that it knows to
compile and execute the whole line.

> use Some_Module_In_lib_Dir;
> 
> 
> If $Bin and $file_path are printed to screen, they show values
identical to
> the path used in the third example and that one derived in the fourth
> example. So, why does $Bin get added to @INC before the program tries to
> load Some_Module_In_lib_Dir, and $file_path does not?

Printing happens at runtime, but the 'use' happens at compile time, as
do the setting of variables, *unless* they specifically happened at
compile time for some reason.

You can use C<BEGIN> blocks to when items are executed, aka if you want
them to be run during compile time.

HTH,

http://danconia.org



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to