in reply to Re: Strange issues with mod_perl and use lib
in thread Strange issues with mod_perl and use lib
That doesn't fix the problem. The assignment is done earlier than it would have without the BEGIN, but it still happens after the use statement is executed.
While the BEGIN block is executed as soon as it finishes compiling, the same goes for the use statement. Since the use statement is fully compiled before the BEGIN block is fully compiled (i.e. it ends first), the use statement is executed before the BEGIN block is executed, and therefore before the assignment is executed.
Solutions:
my $path; BEGIN { # Code that determines the path and stores it in $path. $path = "/www/domain/cgi-bin"; } use lib $path;
or
use lib do { # Code that determines the path and returns it. "/www/domain/cgi-bin" };
or
sub get_lib_path { # Code that determines the path and returns it. return "/www/domain/cgi-bin"; } use lib get_lib_path();
or
# Hardcoded use lib "/www/domain/cgi-bin";
Update: Clarified the wording.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Strange issues with mod_perl and use lib
by Joost (Canon) on May 17, 2007 at 22:08 UTC | |
by ikegami (Patriarch) on May 18, 2007 at 14:17 UTC |