开发者

Pass textbox input to perl script on server

Sorry in advance for a potentially dumb newbie question, but here goes.

I am learning web app programming and I would like to have an input textbox on my webpage where the user enters some text. T开发者_运维问答hen I capture that text and pass to a perl script which generates some output. I then take this text output and pass it back to the webpage.

Can someone point me in the right direction on how to do this.

Can be a really simple example, where the user inputs some text. I take the text and pass to a perl script which turns everything to uppercase - uc() - and then passes back to the webpage.

Thanks


In your html body:

<FORM ACTION="/cgi-bin/results.pl">
<P>Enter a value: <INPUT NAME="value">
<P><INPUT TYPE="SUBMIT" VALUE="Next">
</FORM>

In your results.pl:

use CGI qw(:standard); 
my $value = uc(param('value'));
print header;
print start_html;
print p($value);
print end_html;


The page needs to contain a form. The action attribute of the form needs to point to a URL that your webserver will process with the Perl program. The simplist way to achieve this is using CGI, a more modern approach uses PSGI. Most Perl form processing libraries use a similar interface to CGI.pm's


useCGI;

my $q = CGI->new;
my $text_box_value = $q->param( 'my_text_box_name' );

This is a decent CGI tutorial: http://www.tutorialspoint.com/perl/perl_cgi.htm . Or there's this http://www.cgi101.com/book/ or this http://www.lies.com/begperl/ or this http://websitehelpers.com/perl/ all found here: http://www.google.com/search?q=perl+CGI+tutorial

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜