Scalar Data

Reading data from Standard Input

Example (get_nr.pl):
#!/usr/bin/perl

print "Please enter a number: ";
$n = <STDIN>;

print "number: $n";
STDIN denotes Standard Input, which is usually the terminal from which the program was invoked.

During the execution of a Perl program, each time the term <STDIN> is encountered, the program stops and waits for the user to enter some characters followed by a newline (Return).

The entered strings will then become the value of <STDIN>.

Note: These rules hold if <STDIN> was written in a place where a scalar value was expected, e.g. if <STDIN> is assigned to a scalar variable.


Table of Contents.
Previous | Next.