Problems? Is your data what you think it is? | |
PerlMonks |
(jeffa) Re: Trouble passing parameters into HTMLby jeffa (Bishop) |
on Aug 16, 2002 at 15:11 UTC ( [id://190664]=note: print w/replies, xml ) | Need Help?? |
First, switching from TripodCGI.pm to CGI.pm is a breeze.
Just replace this:
with this: Now, you really should also be using strict.pm as well, which (among other Good Things™) forces you to declare your variables. tye has given the Monastery an excellent writeup on strict.pm - read it! A couple of the cool features of CGI.pm are it's function interface (importing it's subroutines right into your script so you just type param() instead of $CGI->param()) and it's methods for generating HTML, such as p(), h2(), and form elements. So, with that in mind - here is a rewrite of your script: So, how does it work? First, we use CGI.pm - that qw(:standard) bit is just a fancy way of telling CGI.pm that we want to be lazy and import some standard functions like param(),header(),h2(), etc. into our script's namespace. Next, we check for a paramater named 'go' - this is going to be the name of the submit button. If it is present, then the user submitted the form. If not, then this is the first time the user has loaded the script, so we need to give them a form to submit. This technique allows you to replace having to use one file to present a form and another file to show the results, and the script is called a reentering script, because it can do one of two or more states. And now, a bonus - the same script using HTML::Template: I won't explain how this works here, you will have to go and read my HTML::Template Tutorial. Also, you will need to install HTML::Template - read tachyon's A Guide to Installing Modules to find out how to install a CPAN module when you do not have root access the box. Good luck! :) jeffa L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In Section
Seekers of Perl Wisdom
|
|