Example seven - Basic I/O


# Example seven - Basic I/O.
# Reading from standard input is introduced.
#
# by Al Bento

# A first example with simple I/O.

print "Enter one value\n";    # ask for input in STDIN
$a = <STDIN>;    # reads one line from input.
chop($a);    # removes the newline (\n).
print "The single input was $a\n\n";    # prints the input value.

# too many commands lets simplify

print "Enter a new value, or Control-C to end\n";

while (<STDIN>)    # same as: while ($_=<STDIN>)
{chop;    # the $_ variable is implicit

# the above without comments: while (<STDIN>)   {chop;

print "      The new input was $_\n\n";
print "Enter a new value, or Control-C to end\n";
}

print "\n";

download the script


This page is maintained by Al Bento who can be reached at abento@ubmail.ubalt.edu. This page was last updated on June 15, 1997. Although we will attempt to keep this information accurate, we can not guarantee the accuracy of the information provided.