You don't want to use the multiple cgi thing.. It really doesn't serve a purpose in this case.
Ok, so to get this straight, you are saving parameters across sessions and need to re-access those paramaters, keeping intact any new paramaters that come along?
Looking at save() from CGI, it basically writes a file of key=value pairs, one per line.. also, throwing other info at param() will add those key=value pairs to the list.
With that info, this might help:
#!/usr/bin/perl -Tw
use CGI;
my $cgi = new CGI;
# show current list
print "\n\n";
print join(" ",$cgi->Vars());
print "\n";
if (open(FILE, "<./saved_params.txt")) {
# add saved parameters
while(<FILE>) {
chomp;
# CGI's save() ends the file
# with = alone on the last line
last if $_ =~ /^=$/;
# split out the key=value pair
my($key, $val) = split(/=/,$_,2);
# and add them to the current list
$cgi->param($key=>$val);
}
}
# show final list
print "--\n";
print join(" ",$cgi->Vars());
print "\n\n";
# save final list
if (open(FILE, ">./params")) {
$cgi->save(FILE);
close(FILE);
}
I ran this from the cmd line, so it won't work as is in a web environment (no print $cgi->header in there). Also, it doesn't do any checking for a parameter that's already existing, so if the original list had like foo=bar and there was a saved foo=baz, the baz would overwrite bar (i would imagine), but that should be easy enough to check against.
Hopefully that'll help you with what you're trying to do.
-Syn0
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.