On Sun, 28 Jul 2002, Will wrote:
> Suppose from the html I have to parameters coming in: "name"="will"
> and "age"="20"... when they are passed to a script running both
> CGI.pm and HTML::Template... can I then just use them anyway I want
> simply by invoking param("name") or param("age") anywhere in the
> script...?
Ok, here goes:
use CGI;
my $cgi = new CGI;
my $name = $cgi->param("name");
# Note the $cgi-> before the param. It says that param is a method of
# the CGI object named $cgi.
use HTML::Template;
my $t = new HTML::Template(filename => 'mytemplate.tmpl');
$t->param("name" => "Philip");
# Note the $t-> before param. It says that param is a method of the
# HTML::Template object $t.
# You can also do this, although there are better ways
$t->param("name" => $cgi->param("name"));
# which would transfer the CGI parameter name to the HTML::Template
# object $t. The better way to do that would be:
my $t = new HTML::Template(filename => 'mytemplate.tmpl',
associate => $cgi);
The only way for you to use the param() method without qualifying it
with an object first is if you import it into your program like this:
use CGI ':standard';
Then you could just say:
my $name = param("name"); # no need of my $cgi = new CGI;
$t->param("name" => param("name"));
However, I don't particularly advocate importing all the CGI methods
into your namespace. For one, it pollutes your namespace, and secondly,
it makes things very confusing when you have two methods of the same
name, one bound to an object and one not.
HTML::Template does not export its methods to your code. You *must*
always use them bound to an object.
Philip
-------------------------------------------------------
This sf.net email is sponsored by: Dice - The leading online job board
for high-tech professionals. Search and apply for tech jobs today!
http://seeker.dice.com/seeker.epl?rel_code=31
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users