in reply to Modifying Parameter Values w/CGI.pm

Greetings all,
Though Im not sure why you are manually altering your query string, I will leave that alone.
Here is something I was messing around with to hopefully get your desired functionality.
sub modify_query_str { #takes the parameter you wish to modify and the value you wish to set +it to. return $ENV{'QUERY_STRING'} unless(scalar @_ == 2); my ($key, $value) = @_; #Below is the substitution used in CGI::Util for the escape function. $value =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; my %values = map{split /=/,$_;} split /&/, $ENV{'QUERY_STRING'}; $values{$key} = $value; return join("&", map{"$_=$values{$_}"}keys %values); }

Simply I know but is that what you are looking for?

-InjunJoel
"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

Replies are listed 'Best First'.
Re^2: Modifying Parameter Values w/CGI.pm
by rtwingfield (Acolyte) on Jan 05, 2005 at 01:34 UTC

    Regarding your comment, "not sure why you are manually altering your query string", . . .a fair question. In fact the authors (ibid., p.95) comment "It may seem odd that you would ever want to modify parameters yourself, . . .Setting parameters is useful for many reasons, but especially when assigning default values to fields in forms."

    Thanks for your suggestion. Looks like it will work. Still, I wonder why such a method function is not workable within CGI.pm (module). I'm new to Perl modules, etc., and I wonder if I'm just not "getting it?"

    There may even (probably) be a better approach to my immediate purpose. I've designed a module that will handle single transactions: Inquire, Update, Insert and Delete, on a MySQL database table. The module is totally generic, and will accept a parameter list consisting of $host_name, $db_name, $userid, $passwd, $table, and $pkey. To wit, I have also created a module that copies-in these "standard" parameters, and optionally contains a subroutine that will print the six hidden fields that can become parameters in the query string. My concept is analogous to using copy-books in COBOL, the #include in RPG's, or the include etc.h (file) in C. What I've discovered it that if a parent pgm-A (that does not specify a value for $table) calls child pgm-B, and this child makes the decision to specify the Vendor Master Table (in my application, the user has transversed through a host server/database login, and has made an application selection from a menu of business applications), then it is apparently difficult to insert the literal value "vndr_mstr" into the query string already containing the parameter, "&table=", i.e., (NULL), that will eventually be presented to my DBI_API.pm module.