- The perl expression <STDIN>, aside from being
irritating to write in native HTML format, allows you to read from the
pipe named STDIN.
- <STDIN> is the standard source for user input data
for a program on any computer you are likely to see.
- Evaluating <STDIN> in a scalar context gives the
next complete line of user input, or undef if the input pipe has
terminated.
- Example:
# Load the next line the user types in. Block til they hit enter.
$userInput = <STDIN>;
- Evaluating <STDIN> in an array context loads the
rest of the user inputs (the perl program blocks until the input pipe
is terminated) into the specified array.
- Example:
# Load everything the user types in. Block til they hit CTRL-D.
@userInput = <STDIN>;
- There is a secret perl variable named "$_". This
variable is shorthand for the last variable to have been operated on,
and is the default argument for many perl operators.
- Example:
# Echo everything user types back to screen in an especially cryptic fashion
# Look Ma! No Arguments.
while ( <STDIN> ) {
chomp;
print;
}