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

I can easily pass data from form to script with.
print <<END_ERR_HTML; <HTML> <form method=POST action=viewdata.cgi> <font size="4" color="#FF0000">Enter data here.</font> <input type=text name="handle" size=30> <input type=submit VALUE="View Data"> </form> </html> END_ERR_HTML

And retrieve with
print "Content-Type: text/html\n\n"; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/<([^>]|\n)*>//g; $value =~ s/\r//g; $value =~ s/\n/<br>/sgm; $POST{$name} = $value; } @scald = ($POST{'handle'}); $data = $scald[0]; print "$data";

But what if I have this simple little script.
#!/usr/bin/perl $now = name; $wanted = somedata; print "Location: open.cgi?id=$now\n\n"; exit;

In this case I have no form to work with
How on earth can I pass $wanted to the second script open.cgi
And retrieve it in script open.cgi
I have retrieved $wanted by sending it to a database first and
Then retrieving it from the database in the second script.
Surely that is the long way round.
I find the simplest little things are the most perplexing.

Replies are listed 'Best First'.
Re: Passing data from script to script.
by dorward (Curate) on Dec 13, 2006 at 15:42 UTC

    <font size="4" color="#FF0000">Enter data here.</font>

    FYI, modern HTML uses label and style sheets.

    How on earth can I pass $wanted to the second script open.cgi

    There are a number of options. For that example, I'd likely use URI to build a URL with the data in the query string and redirect to that.

      This is correct. But, if you want to pass a lot of things between CGIs, you'll probably be better off passing a session identifier between scripts and storing the values in a database.
Re: Passing data from script to script.
by liverpole (Monsignor) on Dec 13, 2006 at 15:58 UTC
    Hi nasa,

    You could look into using Storable.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: Passing data from script to script.
by SFLEX (Chaplain) on Dec 13, 2006 at 17:05 UTC
    you could use CGI to get the form and url inputs!
    I have found it to work very well and it has many other functions for web scripts.
    # Load CGI.pm use CGI qw(:standard); $CGI::POST_MAX = 1024 * 100; $CGI::DISABLE_UPLOADS = 1; $CGI::HEADERS_ONCE = 1; my $query = new CGI; # Get inputs my $id = $query->param('id') || ''; my $handle = $query->param('handle') || '';

    it also redirects.
    print $query->redirect(-location=>"http://www.yourdomain.com/open.cgi");

    CGI.pm does a lot more for web scripts like Cookies and HTML, est... If you have not used it try it out its a Default Perl Module.