in reply to Multiple CGI Objects w/ Same Name
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.#!/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); }
|
|---|