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):
  1. 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.
  2. 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.
  3. 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 }
  4. 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.

In reply to Passing values to a Perl script from PHP by Yary

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.