How do I set Perl’s %ENV to introduce a Perl script into the context of my web application?
I have a website, written in a language different from Perl (Python). However I need to use a Perl application, which consists of a .pl file:
#!/usr/bin/env perl
"$ENV{DOCUMENT_ROOT}/foo/bar.pm" =~ /^(.+)$/;
require $1;
my $BAR = new BAR(
user => 'foo',
);
print $bar->get_content;
… and a module bar.pm, which relies on "$ENV{HTTP_HOST}", "$ENV{REQUEST_URI}",
"$ENV{REMOTE_ADDR}" and "$ENV{DOCUMENT_ROOT}".
How should I set this hash? This is my very first experience with Perl, so I may be missing something really obvious here 🙂
If you’re spawning that Perl process from your Python code (as opposed to “directly from the webserver”), there are several ways to set the child process environment from the Python parent process environment, depending on what you’re using for the “spawning”.
For example, if you’re using
subprocess.Popen, you can pass anenv=argument set to the dictionary you desire, as the docs explain: