Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print form elements when CGI is used

Status
Not open for further replies.

safra

Technical User
Jan 24, 2001
319
NL
Apparantly This is not possible:

use CGI qw:)cgi);
my $iq = new CGI;

print "something $iq->param('newUser') and more";

this tries to print the $part as a hash.

Does Perl has a function that will make this possible or do I really need to parse the form element first into a scalar and then use the scalar in the print part?

Ron
 
you can do this:[tt]
print "this calls a ", $var->param('word'), " fuction.\n";
[/tt]
and it should work.
or, if you wanna be really naughty, break encapsulation, and go against all object orientedness CGI has or that anything in perl has, you can use the fact that there's no such thing as private in perl, and that the variable you make the 'new CGI' is actually a reference to a hash, the exact hash you're accessing when you make calles to 'param'.
DON'T DO THIS. i have only included it for educational purposes. it's bad style, even for a cgi-script :)

:) "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Yes, thanks stillflame. The example I gave is a bad example as I most of the time use something like this to print to the window:

print <<HTML;
HTML

So I will have to parse each form element first,

Ron
 
wait, try this. leave it in the doublequotes, but then call it like this:[tt]
print &quot;words words words ${var->param('name')} words&quot;;
[/tt]
the curly brackets will make sure that the contents are evaluated as they should, i think. try that, see if it works. &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
I just tried it, this is the error that was returned:

&quot;Can't locate object method &quot;param&quot; via package &quot;iq&quot; at control.cgi line 193&quot;

Any ideas if this can be solved?

Ron
 
Hmm. well, i think i've found a syntax to do it with, but i bet there's a better way. try this[tt]
print &quot;value = ${\($var->param('key'))}, so there!&quot;;[/tt]
&quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
I'll try that stillflame! Thanks for your help. I was about to write that probably parsing the form element first would be easier. But actually it isn't as everything together will take more code. So I'll try it out!

Regards,

Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top