Perl Questions?
June 3rd, 2010 | by admin |I have this peice of code which is in AspLanguage :
response.write "&name1=" & request("param1") & "&name2=" & request("param2") & "&"
response.end
How would I do that exact code in Perl?
Thankyou for your help
James
To clarify the other answer, request() appears to be a special ASP function call that will allow you to retreive the request parameters by name. That exact feature is not part of perl itself, but the CGI module may get you what you want. The sample below will import the param() function into your package such that you can emulate the ASP more closely. As I understand, the standard import here will also magically examine the environment variables of the running process and parse the query string, headers, etc. which is how it can expose the request parameters so simply. For more info on processing your CGI request, you should take a look at CGI::Request.
use CGI qw(:standard);
print ‘&name1=’ . param("param1") . ‘&name2=’ . param("param2") . ‘&’;
Also since you seem new to perl and I don’t know ASP, I’ll mention that the goal of the CGI is just to write to STDOUT. It looks like in ASP you have a special object with a write method that represents the output to the user, but in CGI scripts, the expectation is that the webserver will just execute the script and return the STDOUT as the response.
2 Responses to “Perl Questions?”
By martinthurn on Jun 3, 2010 | Reply
print ‘&name1=’, request(‘param1′), ‘&name2=’, request(‘param2′), ‘&’;
print "\n";
References :
By Ajith A on Jun 3, 2010 | Reply
To clarify the other answer, request() appears to be a special ASP function call that will allow you to retreive the request parameters by name. That exact feature is not part of perl itself, but the CGI module may get you what you want. The sample below will import the param() function into your package such that you can emulate the ASP more closely. As I understand, the standard import here will also magically examine the environment variables of the running process and parse the query string, headers, etc. which is how it can expose the request parameters so simply. For more info on processing your CGI request, you should take a look at CGI::Request.
use CGI qw(:standard);
print ‘&name1=’ . param("param1") . ‘&name2=’ . param("param2") . ‘&’;
Also since you seem new to perl and I don’t know ASP, I’ll mention that the goal of the CGI is just to write to STDOUT. It looks like in ASP you have a special object with a write method that represents the output to the user, but in CGI scripts, the expectation is that the webserver will just execute the script and return the STDOUT as the response.
References :
http://perldoc.perl.org/CGI.html