| Contents | Up | Previous | Next |
In order to receive a value from the user perl supplies the <> operator. When entered, this operator reads a line from the console, and returns it (along with the newline).
Here's an example:
print "Please enter your name:\n"; $name = <>; chomp($name); print "Hello, ", $name, "!\n"; |
Notice the chomp function which strips off the trailing newline character from the variable. You would usually want to use it, when getting input from the user.
Here's another example:
print "Please enter a string:"; $string = <>; chomp($string); print "The string you entered contain ", length($string), " characters.\n"; |
| Contents | Up | Previous | Next |