hmbscully has asked for the wisdom of the Perl Monks concerning the following question:
I know OO style of CGI programming is more accepted and is usually the way that examples of the CGI.pm are done. I have a lot of code that I maintain that is all written in the function-oriented style. Honestly, I didn't even realize that was what it was called until recently. I'm reading a lot of OO style examples that make sense, but I want to understand how to answer my question in function-oriented style.
I need to read in the parameters from a form and return another page based on the values of each parameter. The form elements are all radio buttons, so I don't have to worry about the multivalued null character issue here.
I'm unsure about importing CGI.pm routines into the script namespace and then how to use the param() method. I read something about using use CGI ':cgi-lib'; instead of use CGI qw(:standard) to be able to get the parameter list as a hash using Vars, but I don't understand that.
Something like this?
#!/usr/bin/perl -w # tools.cgi use CGI qw(:standard :cgi); use CGI::Carp qw(fatalsToBrowser); require 'sri.conf'; %params = Vars; #getting the hash with the parameter list as the keys # Print HTTP header and opening HTML tags. print "Content-type: text/html\n\n"; # Print the top of the page &print_file($action_header_file); #this while is just an attempt to get the variable names and values to + print for my understanding, to be replace by other code using these +values while (my ($variable_name, $variable_value ) = each %params) { print "Variable name = $variable_name/n Variable value = $variable +_value\n\n"; } # Print the bottom of the page &print_file($action_footer_file); sub print_file { my($file_name) = @_; #name subroutine variables open(HEADER,"$file_name"); print <HEADER>; close HEADER; }
TIA
~W
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Function-oriented style CGI accessing form parameters
by Your Mother (Archbishop) on Aug 03, 2005 at 17:41 UTC | |
by hmbscully (Scribe) on Aug 03, 2005 at 18:25 UTC | |
by Your Mother (Archbishop) on Aug 03, 2005 at 20:49 UTC | |
by hmbscully (Scribe) on Aug 03, 2005 at 21:14 UTC | |
|
Re: Function-oriented style CGI accessing form parameters
by jhourcle (Prior) on Aug 03, 2005 at 17:56 UTC | |
by hmbscully (Scribe) on Aug 03, 2005 at 18:20 UTC | |
|
Re: Function-oriented style CGI accessing form parameters
by kwaping (Priest) on Aug 03, 2005 at 16:44 UTC | |
by hmbscully (Scribe) on Aug 03, 2005 at 17:04 UTC |