I am posting this question & my response, which came into the CPAN::Testers list. This seems like a better place and I am directing the original poster to this node. Thanks to the fellow monks who helped this fellow out on the mailing list before now.
On Sun, Mar 29, 2015 at 11:26 PM, Uday Shankar Kintali wrote:
> Looking if I can pass on the user selected values ( in php form) to the perl script.
Since you are calling the script using "system", there are a few general ways of getting the caller (PHP in this case) parameters to the callee (Perl):
- Environment variables. If you can set them in PHP before calling system, you ought to be able to retrieve them in Perl using $ENV{Env_var_name}, replacing "Env_var_name" with whatever environment variable you want to read. This seems the safest to me for simple use.
- Command-line arguments. If in PHP you run "system 'perl_script.pl arg0 arg1 arg2'", then Perl will have the arguments in @ARGV. $ARGV[0] eq 'arg0' && $ARGV[1] eq 'arg1', etc. Be careful if any of your arguments have spaces or shell-special characters like quotes, pipes- unless PHP has a form of "system" that takes care of those for you. Perl's "system" will do so, if you pass "system" a list or array instead of a string/scalar, but I don't know about PHP, and you are calling "system" from PHP.
- Pipe the data into Perl. A quick scan of PHP documentation says to do something like this:
$handle = popen('PerlCode.pl','w');
fwrite($handle,"here is some input\n");
fwrite($handle,"more input\n");
# etc....
pclose($handle);
and then in Perl you can read it like:
while (<STDIN>) {
# Do something with the line we just read
}
- Some mutually agreed upon data store: a file, a database, shared-memory cache, etc. Need to be careful about handing the right data to the right process, if there's any chance of there being multi-process, and also careful about data lifetime- cleaning up old values, but not too soon. I won't go into the details here.