0

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. Then 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

3 Answers 3

4

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;
Sign up to request clarification or add additional context in comments.

3 Comments

hmmm.. somehow i get 500 internal server error when running this. not sure what i am doing wrong. i checked that i have cgi.pm so that's not issue.
@racket99 Usually this means your script isn't compiling. What do you get when you run it from the command line? ./results.pl
actually i didn't make it executable. my bad. it works now.
0

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

Comments

0

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

1 Comment

Thanks, but how do I get the text from the webpage to this script?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.