By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,852 Members | 2,259 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,852 IT Pros & Developers. It's quick & easy.

Perl Script that gets data from a form

P: 67
Alright I just want to get the entered data from the html form and process it to store it as a variable can someone give me an example of this please.

Expand|Select|Wrap|Line Numbers
  1. #!c:\perl\bin\perl -t
  2. use strict;
  3. use warnings;
  5. $user_input = 
I'd like the $user_input to be whatever the user entered in the guessedNumber text input.

Expand|Select|Wrap|Line Numbers
  1. <form METHOD="POST" ACTION="guessNumber.cgi">
  2. Guessing Game<br>
  3. <br><br>
  4. Enter a number between 1 & 100 <br>
  5. Guess:  <input type="text" name="guessedNumber" maxlength=3 size=5><br>
  6. <input type="submit" value="Enter Guess">
  7. <input type="reset" value="Reset"><br>
  8. <input type="hidden" name="msgDisplay" value="Display Message">
  9. </form>
Feb 22 '09 #1
Share this Question
Share on Google+
5 Replies

Expert 100+
P: 971
If you search this forum you will find many examples of getting data from a form. Here is a link to a script I did as an example. It also uses HTML::Template.

It is a nice example. Also, check the documentation for the as well.

Feb 22 '09 #2

P: 67
Could you just make an example from the information I gave or am I lacking information to give an example or is my question to complicated to give a quick example? It's just I find your example long and complicated and a little hard to understand for what I need to do.
Feb 22 '09 #3

Expert Mod 2.5K+
P: 3,503
In the future, please do try and search Google for the answers that you seek before posting here. You will learn more if you get the answer on your own and figure it out than if you wait for an answer here.

A quick google search like this would have provided plenty of links for you to figure this out.


Feb 22 '09 #4

Expert 100+
P: 971
Your example is not to complicated. Here is a more basic example.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -T
  3. use strict;
  4. use warnings;
  6. use CGI;
  7. use CGI::Carp qw/fatalsToBrowser/;
  9. my $q = CGI->new;
  10. my $user_input = $q->param('guessedNumber');
  12. print $q->header;
  13. print $user_input;
  15. 1;
Is that more of what you are looking for?

Feb 22 '09 #5

P: 67
Yea thanks for simplifying that.
Feb 22 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.