cancel
Showing results for 
Search instead for 
Did you mean: 

Perl Environment Variables missing

UncleZen
Grafter
Posts: 86
Thanks: 6
Registered: ‎15-08-2008

Perl Environment Variables missing

In my perl scripts, I use the following environment variable:
$ENV{C_DOCUMENT_ROOT}
to get  the path to to root of the webspace (e.g. /files/home1/username etc)
That env variable no longer exists, as such some of my perl scripts that read/write files are failing.
I have a perl script that prints them all out here:
http://ccgi.unclezen.plus.com/cgi-bin/dev/test/printenv.pl
As you can see this particular env variable is missing and there doesnt seem to be an equivalent.
Help!
2 REPLIES
Superuser
Superuser
Posts: 9,884
Thanks: 1,248
Fixes: 71
Registered: ‎06-04-2007

Re: Perl Environment Variables missing

$ENV{C_DOCUMENT_ROOT} was a non-standard variable and, as you say, is no longer present. The "official" one is DOCUMENT_ROOT but that was not suitably set before, and isn't now.
I suggest you build your own value by accessing SCRIPT_FILENAME and strip SCRIPT_URL from it. That's the approach I use which works fine.
In PHP I use
preg_match("£(.*){$_SERVER['SCRIPT_URL']}\$£", $_SERVER['SCRIPT_FILENAME'], $matches);
$docroot = "{$matches[1]}/";
David
Edit: added PHP example
David
UncleZen
Grafter
Posts: 86
Thanks: 6
Registered: ‎15-08-2008

Re: Perl Environment Variables missing

Thanks, I was rather hoping not to have to write a piece of code. I was hoping things would work as before, like nothing had gone wrong. But if I have to its no sweat. Maybe plus net will add this or an equivalent env variable