Accepting user input
This page shows different ways to accept user input using perl.
Accepting user input from the command line
There are a number of ways to accept command line input. Firstly you can use the @ARGV array:
Note that $ARGV[0] actually is the first argument and not the program name.
Or if you need a bit more flexibility, use the Getopt::Std module:
If you called the above program as follows:
The output would be:
Accepting user input from a terminal
You can read directly from standard in with the angle operators <>.
You could use the angle operators without the word ‘STDIN’:
Accepting user input graphically
The code below will display a perl Tk widget, with text field and two buttons. Enter some text in the text field then press the ‘Click here’ button. You will see the text you typed appear in your terminal. When you are finished click the ‘Done’ button.
Accepting user input from a web form
Use the CGI module, create a CGI object (in the variable $q in our case), and call the CGI method param() to retreive the form values. The example below also prints out the form: