Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Calling a perl script and passing parameters from html

by HannibalRex (Initiate)
on Nov 16, 2012 at 21:36 UTC ( #1004247=perlquestion: print w/replies, xml ) Need Help??
HannibalRex has asked for the wisdom of the Perl Monks concerning the following question:

So I have a perl script that someone else wrote, accepts command line parameters to run, I'm trying to "web enable" this script. The way I think of it is a form submit/post to the script, and the script accepts the values passed to it from entries on the web page. For example, this script creates a given number of random numbers based on a seed, so on the cmd lind it looks like ./ --numcards=10000 --seed=25 --blurb="10000 cards for JoMama" Can someone point me to a reference on how to do this? I've been told it would be best to do it in Python and use a system call, which I honestly have no idea how to do. So, I'd really like to know how to do this, not just hack it. I'm really needing a push in how to do this, and where a good reference may be located. Everything I keep googling just seems too complicated, or not really what I am looking for. Is it not common to use a web interface to do sys or db activities through perl? Sorry, I'm an old C guy, so I don't really understand the web parts of perl and or python yet. TIA!

  • Comment on Calling a perl script and passing parameters from html

Replies are listed 'Best First'.
Re: Calling a perl script and passing parameters from html
by Anonymous Monk on Nov 17, 2012 at 00:39 UTC
Re: Calling a perl script and passing parameters from html
by Jenda (Abbot) on Nov 17, 2012 at 17:26 UTC

    If the script doesn't take too long to execute and you do not need to process it's results then a wrapper script like this should be enough to get you up and running:

    use strict; use CGI; use CGI; my $q = new CGI; @ARGV = (); foreach ($q->param()) { $value = $q->param($_); $value =~ s/"/\\"/g; push @ARGV, "--" . $_ . '="' . $value . '"'; } do 'path/to/the/';

    All it does is it moves the parameters from the querystring or post into the @ARGV array (array of script parameters) in the format required by the script and then executes the script without starting a new process.

    As long as the script prints its results to STDOUT they should be sent to the client browser.

    Enoch was right!
    Enjoy the last years of Rome.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1004247]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2017-03-25 20:30 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (313 votes). Check out past polls.