Home » Perl stdin

Perl STDIN

In Perl programming, we can get input from standard console using <STDIN>. It stands for Standard Input. It can be abbreviated by <>. So,

is equivalent to:

Perl Input from User using <STDIN>

Let’s see an example where we are getting data from the user using Standard Input <STDIN>.

Type in:

Here, $name is a scalar variable. Variables are declared using my keyword. After running this script, it will ask for your name. Type your name in the console and press ENTER.

Output:

Enter your Name: John Welcome John   at tutoraspire. 

As you can see in the above output, a new line is added after printing the name. To overcome this problem, add the chomp function with $name as shown below.

Output:

Enter your Name: John Welcome John at tutoraspire. 
Next TopicPerl Version

You may also like