Table of Contents

STDIN and other filehandles

Sometimes you have to interact with the user. It is a pain, but sometimes necessary, especially for the live ones. To ask for input and do something with it try this:

print "Please tell me your name: ";
print "Thanks for making me happy, $name !\n";

New things to learn here. Firstly, <STDIN> . STDIN is a filehandle. Filehandles are what you use to interact with things such as files, console input, socket connections and more.

You could say STDIN is the standard source for input. Guess what STDIN stands for. In this case the STDIN filehandle is reading from the console.

The angle brackets <> read data from a filehandle. Exactly how much is dependent on what you do, but in this case it is whatever was input at the prompt.

So we are reading from the STDIN filehandle. The value is assigned to $name and printed. Any idea why the ! ends up on a new line ? on a new line on a newline ????

As you pressed Enter, you of course included a newline with your name. The easy way to get rid of it is to chop it off: