Simon ---

BINGO! Thank you! With the insight you gave me, I wrote a trivial C++ 
program I ran on my webserver to find out all the present environment vars:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[],char* envp[])
{
         printf("Content-Type: text/html\n\n<html><head><title>Environment 
Variables</title></head><body><pre>\n");
         while (envp && *envp) {
                 printf("%s\n",*envp);
                 envp++;
         }
         printf("</pre></body></html>\n");
         return 0;
}

This produces a web page with all the defined variables. Then I 'primed the 
pump' in PERL to get it to load its %ENV completely.

That is, for every environment variable my C++ program reported, I wanted 
Perl to grab the external data if possible. I discovered I didn't need to 
actually assign anything. I could just do an exists test. Thus, for every 
known possible environment variable, I had a line like the following in my 
Perl script:

if (exists($ENV{'HTTP_ACCEPT'})) { $countem++ }
if (exists($ENV{'HTTP_ACCEPT_LANGUAGE'})) { $countem++ }

Not elegant of course. A qw() creating an array, then a for (@arr) {} would 
have been cleaner. Editor macros sometimes lead to brain laziness. Anyway...

After that, I could iterate over %ENV quite easily:

$outpage .= "<B>Environment variables</B>:<PRE>\n";
my @keys = sort keys %ENV;
my $maxlen = 10;
for (@keys) { $maxlen = length if ( length > $maxlen ) };
for (@keys) { $outpage .= sprintf("%*s = \"%s\"\n",$maxlen+1,$_,$ENV{$_}) };
$outpage .= "$unpre$graf$graf\n\n";

Now I can see that ALL the stuff I needed is available. And I can stop 
downloading this huge IIS manual I was getting off the Microsoft site.

Thanks Simon!

--- John

At 01:30 AM 6/28/02 , Simon Oliver wrote:
> > Liang Anmian wrote:
> >
> > I'm using ActivePerl on Windows. I've been playing around with Perl for
> > ISAPI. I notice that scripts that run under Perl for ISAPI don't have
> > the "ENV" hash defined, meaning I can no longer grab the visitors' IP
> > Address and all other useful stuffs like the HTTP_REFERER variable.
> >
> > Is there any workaround?
>
>They are "grabbed" on the fly - i.e. when you request an environment
>variable PerlIS  gets it from the environment and puts it in the %ENV
>hash?
>
>$title = "Hello Perl";
>$perlxs = $ENV{PERLXS} || "Perl";
>$server = $ENV{SERVER_SOFTWARE};
>$client = $ENV{REMOTE_ADDR};
>print << "EOHTML";
>HTTP/1.0 200 OK
>Content-Type: text/html\n
>
>
>$title
>
>
>
>This is $perlxs Version $] running on $server($^O)
>
>
>Remote Host=$client
>
>
>
>EOHTML
>
>
>--
>   Simon Oliver
>_______________________________________________
>Perl-Win32-Users mailing list
>[EMAIL PROTECTED]
>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to