Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I've got a quandry. I need to write a script that collects information from a user. The ideal way to do this would be to write a CGI script that prints up a pretty HTML form for the user to fill out. When the user clicks "Submit", the script would collect the parameters they've entered, do some processing, and spit out the result into a text file which will be used elsewhere.

That's where the problem comes in. For at least a few months, I won't be able to put this script on a webserver.

What I'd like to do is write one script with a command-line interface that collects the data and puts it in a text file (no processing). This script would then call up a CGI script with input redirected to the text file. The CGI script would do all the processing and create the final output. That way when I am finally able to get this tool on the web, I can just plunk the CGI sript on the server and be done.

So what kind of formatting do I need to have my command-line tool write the paramters to so that the CGI script can read it easily? Does the file need to look like:

key1=value1&key2=value2&key3=value3

Or maybe:

key1=value1
key2=value2
key3=value3

Or what?

Replies are listed 'Best First'.
Re: Redirect CGI input?
by bronto (Priest) on Jun 24, 2002 at 14:10 UTC

    If you are using CGI.pm, use the format specified in the docs of the save method: it seems to be exactly what you need.

    If you don't use it, it's better for you to start as soon as possible!!!

    For more information, perldoc CGI

    Ciao!
    --bronto

Re: Redirect CGI input?
by little (Curate) on Jun 24, 2002 at 14:01 UTC

    Use a redirect header targetting to the other script along with the http-status code 303 (means "see other"). In the URL you must suplly with -uri you can easily add an ID as a reference to the document you created or identify the user in any other way. merlyn wrote a column about Browser Branding.

    Have a nice day
    All decision is left to your taste

    Update

    Regarding the format for that temporary file I'd suggest you look into XML::Simple, or if you can be sure the user will proceed immediately you could _store_ a hash with some values in the first script, pass an identifier to the second script which then _retrieve_s the hash using methods from Storable.pm.

Re: Redirect CGI input?
by mfriedman (Monk) on Jun 24, 2002 at 16:59 UTC
    I think you're looking at this the wrong way. Instead of having your CGI script call your command line program, abstract the logic required to save the data to a seperate module, and create two clients for that module: A command line application and a CGI application.

    That way, it doesn't matter how your command line application actually gets the data for testing, just that it passed the data on to the module in the correct form (Say, a hash ref.)