I am having trouble with CGI.pm. The module seems great and does a lot of
cool stuff but this seems silly.

I have a script that needs to be called several times and collects different
data each time.

So I figgured I could save the state and restore the parameters each time
the script is run. All the documentation suggests this is possible.

The saving the parameters is great but how do you get them back?

I have this test code copied from ActiveState and am playing with it.
Trouble is each time you restore the state you clobber the CGI object, easy
I think I will save the state and then recover all values from the file. As
you can see below it will only recover the first values saved?

How do I get all values in the file loaded? The package is so cool that I
cannot believe there is not an easy way to restore all values.

I could loop through the test.out file and assign the values individually
but it sounds like there must be an easier way?

What am I missing? Are there any resources that do not just rehash this
example? I have found a few but they all show the same example.

Thanks for any help.

Kevin


Program run first time.

#!/usr/bin/perl
use CGI;
open (OUT,">>test.out") || die;
my $q = new CGI;
$q->param(-name=>'junk',-value=>'Hello');
$q->param(-name=>'MUM',-value=>'Wave');
$q->save(OUT);
close OUT;

# reopen for reading
open (IN,"test.out") || die;
my $q = new CGI(IN);
print $q->Dump;
close IN;

Produces this  in test.out
junk=Hello
MUM=Wave
=

and prints

<UL>
<LI><STRONG>junk</STRONG>
<UL>
<LI>Hello
</UL>
<LI><STRONG>MUM</STRONG>
<UL>
<LI>Wave
</UL>
</UL>

Second time run change a few values to simulate script being called again
from browser

#!/usr/bin/perl

use CGI;
open (OUT,">>test.out") || die;
my $q = new CGI;
$q->param(-name=>'2junk',-value=>'Hello');
$q->param(-name=>'22MUM',-value=>'Wave');
$q->save(OUT);
close OUT;

# reopen for reading
open (IN,"test.out") || die;
my $q = new CGI(IN);
print $q->Dump;
close IN;

When run prints
<UL>
<LI><STRONG>junk</STRONG>
<UL>
<LI>Hello
</UL>
<LI><STRONG>MUM</STRONG>
<UL>
<LI>Wave
</UL>
</UL>

Produces this in test.out
junk=Hello
MUM=Wave
=
2junk=Hello
22MUM=Wave
=


Reply via email to