[prev in list] [next in list] [prev in thread] [next in thread]
List: perl-win32-users
Subject: Re: Perl for ISAPI
From: John Deurbrouck <john () pcpix ! com>
Date: 2002-06-28 18:36:58
[Download RAW message or body]
I tried to optimize by doing this:
#prime the %ENV pump with all actual environment variables
my @env_vars = (`envdump.exe` =~ /(.+?)=.*\n/g);
for (@env_vars) { if (exists($ENV{"$_"})) { } }
Unfortunately it doesn't work, because the child process isn't created with
a new copy of the parent environment, but rather the %ENV data. Thus you
end up with the same list in %ENV you had at the beginning.
Here's the code I ended up with, which makes the effort to delete strings
that don't exist in the environment.
#prime the %ENV pump
{
@env_vars = qw (
# this should be the list of env vars you're
interested in, perhaps generated by the tool from the previous post
# abbreviated to conserve bandwidth
HTTP_ACCEPT
HTTP_ACCEPT_LANGUAGE
HTTP_CONNECTION
HTTP_HOST
HTTP_REFERER
HTTP_USER_AGENT
HTTP_ACCEPT_ENCODING
QUERY_STRING
REMOTE_ADDR
REMOTE_HOST
REQUEST_METHOD
);
for (@env_vars) {
if (exists($ENV{$_})) {
if (!defined$ENV{$_} or length($ENV{$_})<1) { delete $ENV{$_} }
}
}
}
--- John
>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...
>
>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.
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic