CGI passing arrays/hashes to another CGI script

If I have a Perl CGI script (script01), which fills an array(s) with information and outputs a HTML page with a link to another CGI page (script02); is there anyway to pass the array(s) from "script01" to "script02" when the page visitor clicks the link?

Hope that makes sense!

:slight_smile:

One way to do it is to have the first script write the array to a file and have the second script read the file into an array, provided the scripts are on the same box.

Are they on the same box?

Hmm. Or you can better do it this way:

You can have script1 generate HTML containing a form (POST HTTP-method) with all your items specified by hidden fields, i.e. generate something like

<form action="script2.cgi" method="post">

<!-- Hidden fields -->
<input type="hidden" name="item0" value="value0">
<input type="hidden" name="item1" value="value1">
<!-- hidden fields end here-->

<input type="submit" value="submit">
</form>

When the visitor hits the submit button, the hidden fields are sent and by reading the form you can parse and get the (item0, value0), (item1, value1) pairs.

If you insist on a hyperlink, then the only method you can pass the info to script2 is by HTTP GET, i.e. on the URL as params. Script1 generates HTML containing a link with href "script2.cgi?item0&item1&..."

Your script then parses the env. variable $ENV{'QUERY_STRING'} and gets all key-value pairs to form the array again.

You will first need to convert the special characters in the array items (say @) into the % form (i.e. %40) in order to form a valid URL.

All such item mangling should be easy if you use CGI.pm.

Of course I prefer the POST method, as the URL is less noisy, and this is the method I use, right now.