Thursday, January 6, 2011

STDIN and STDOUT filehandles in Perl

STDIN is responsible for accepting data from the standard input(e.g: keyboard)
and STDOUT is responsible for transmitting data to standard output(e.g: screen).

#!/usr/bin/perl

print "Enter your name and hit enter:";
chomp($name=<stdin>); # accepting data for name from the end user and storing it in a variable without the new line

print "Enter your age and hit enter:";
chomp($age=<stdin>); # accepting data for age from the end user and storing it in a variable without the new line

print STDOUT "your name is $name and you are $age years old\n"; # STDOUT is optional, as the standard output is screen/ monitor by default