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,

snippet
my $name = ;

is equivalent to:

snippet
my $name = <>;

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:

snippet
use 5.010;
use strict;
use warnings;
say "Enter your Name:";
my $name = ;
say "Welcome $name at JavaTpoint.";

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:

Output
Enter your Name: John Welcome John at JavaTpoint.

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.

snippet
use 5.010;
use strict;
use warnings;
say "Enter your Name:";
my $name = ;
chomp $name;
print "Welcome $name at JavaTpoint.\n";

Output:

Output
Enter your Name: John Welcome John at JavaTpoint.
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents