
| Contents |
|||||||||||||||
| [an error occurred while processing this directive] |
8.1 Reading Input from Standard Input
Input is read from the user via the
The most basic use of the
This script, when executed, will wait for the user type to something and then display that input after the keyboard#!/usr/bin/perl $userinput = <STDIN>; chomp ($userinput); print "User typed $userinput\n";
As you have probably come to expect with Perl there are many ways that the
The above example will continue to read lines until the End of File (EOF) control character is encountered. On a Linux or UNIX based system this is typically represented by the Ctrl-D key. To find out what your EOF character is on a Linux or UNIX system run the stty as follows in a shell window:#!/usr/bin/perl @userinput = <STDIN> foreach (@userinput) { print; }
stty -a stty will display the current setting for your terminal window. Look for the .eof. entry which will typically be configured by default as .^D. (i.e the D key pressed whilst holding down the Crtl key). |