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


In reply to Function-oriented style CGI accessing form parameters by hmbscully

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.